7

我有一个模型,其中有两个字段是其他模型的外键。

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)

阅读了管理文档并尝试了一些事情之后,很明显您确实需要为 grappelli 使用标签“fk”来将自动完成查找格式应用于字段。那么......我怎么能用这个模型做到这一点,有多个外键字段?

4

1 回答 1

11
class HomepageAdmin(admin.ModelAdmin):
   raw_id_fields = ('featured_user', 'featured_story',)
   autocomplete_lookup_fields = {
   'fk': ['featured_user','featured_story'],
   }
于 2012-10-15T12:23:34.687 回答