开发者

Django: admin.StackedInline with no foreign key

I have the following in admin.py

class AdInline(admin.StackedInline):
    model = Ad

class UnitAdmin(admin.ModelAdmin):
    fields = ('user', 'name', 'about', 'url', 'active', 'type')
    list_display = ('user', 'name', 'url', 'created', 'active', 'type')

    inlines = [AdInline]

class AdAdmin(admin.ModelAdmin):
    field开发者_Python百科s = ('user', 'title', 'about', 'url', 'active')
    list_display = ('user', 'title', 'url', 'created', 'active', 'clicks')

Now this is done in mongodb so i don't want relationships.. but I want admin to work.. When I try to load up a unit I get the following error

Exception Value:    <class 'ad.models.Ad'> has no ForeignKey to <class 'ad.models.Unit'>

Ad has no foreign key what so ever. I want all the ads to live inside a unit as a dictionary in mongodb. I just want to leverage the power of django admin's to create them.

any pointers?


Your inline has to have a foreign key to the model you want to include it in, i.e. your Ad needs a foreign key to your unit; that's the way it works. If you can't represent that relationship, then you can't use inlines. I'm not sure what can replicate this behaviour in the admin, but I don't think inlines fit the bill.

https://docs.djangoproject.com/en/dev/ref/contrib/admin/#django.contrib.admin.InlineModelAdmin

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜