我有一个带有两个字段的模型,这些字段是其他模型的外键。
class Homepage(models.Model):
featured_user = models.ForeignKey('auth.user')
featured_story = models.ForeignKey('site_stories.story')
@staticmethod
def autocomplete_search_fields():
return ("featured_user__icontains", "featured_story__icontains",) # Is this right?
class HomepageAdmin(admin.ModelAdmin):
raw_id_fields = ('featured_user', 'featured_story',)
autocomplete_lookup_fields = {
'fk': ['featured_user'],
'fk': ['featured_story'] # <====== What should this be???
}
admin.site.register(Homepage, HomepageAdmin)
在reading the admin docs之后尝试了一些事情,很明显你字面上需要使用标签“fk”为grappelli将自动完成查找格式应用于字段。那么......我怎么能用这个有多个外键字段的模型呢?
答案 0 :(得分:11)
class HomepageAdmin(admin.ModelAdmin):
raw_id_fields = ('featured_user', 'featured_story',)
autocomplete_lookup_fields = {
'fk': ['featured_user','featured_story'],
}