【发布时间】:2011-09-01 10:39:58
【问题描述】:
我想在管理中的多对多关系上使用 raw_id_fields,并且我希望每个相关对象都显示在自己的行上(而不是单个字段中的逗号分隔列表,这是默认行为)。按照在野外发现的例子,似乎我应该能够做到这一点:
# models.py
class Profile(models.Model):
...
follows = models.ManyToManyField(User,related_name='followees')
# admin.py
class FollowersInline(admin.TabularInline):
model = Profile
raw_id_fields = ('follows',)
extra = 1
class ProfileAdmin(admin.ModelAdmin):
search_fields = ('user__first_name','user__last_name','user__username',)
inlines = (FollowersInline,)
admin.site.register(Profile,ProfileAdmin)
但这会产生错误:
<class 'bucket.models.Profile'> has no ForeignKey to <class 'bucket.models.Profile'>
我不清楚我在这里做错了什么。感谢您的建议。
【问题讨论】:
标签: django django-admin django-orm