gpt4 book ai didi

具有多个外键字段的 django-grappelli 自动完成查找

转载 作者:行者123 更新时间:2023-12-04 10:54:31 26 4
gpt4 key购买 nike

我有一个包含两个字段的模型,这些字段是其他模型的外键。

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 将自动完成查找格式应用于字段。那么......我如何用这个模型来做到这一点,其中有多个外键字段?

最佳答案

class HomepageAdmin(admin.ModelAdmin):
raw_id_fields = ('featured_user', 'featured_story',)
autocomplete_lookup_fields = {
'fk': ['featured_user','featured_story'],
}

关于具有多个外键字段的 django-grappelli 自动完成查找,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12852059/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com