【发布时间】:2015-02-22 06:53:33
【问题描述】:
是否可以在 Django 管理中按 GenericForeignKey 对象标题进行过滤?
我想按程序名称过滤,NonSupportedProgram.title 或 SupportedProgram.title (list_filter = (SOME FIELD HERE)),但不知道怎么做?
models.py
class FullCitation(models.Model):
# the software to which this citation belongs
# either a supported software program or a non-supported software program
content_type = models.ForeignKey(ContentType)
object_id = models.PositiveIntegerField()
content_object = generic.GenericForeignKey('content_type', 'object_id')
class NonSupportedProgram(models.Model):
title = models.CharField(max_length=256, blank = True)
full_citation = generic.GenericRelation('FullCitation')
class SupportedProgram(models.Model):
title = models.CharField(max_length=256, blank = True)
full_citation = generic.GenericRelation('FullCitation')
【问题讨论】:
-
不,不一样,因为我在这里尝试使用
GenericForeignKey字段作为ModelAdmin.list_filter和/或ModelAdmin.search_fields中的参数。我不知道如何(或是否可能)使用 ModelAdmin 的搜索和/或过滤方法按我的GenericForeignKey对象的名称搜索/过滤...?
标签: django django-admin generic-foreign-key