我尝试使用 grappelli 获取通用外键的小部件。这是我需要得到的:http ://code.google.com/p/django-grappelli/wiki/generic_2_1 。我有一个模型:
class Circuit(models.Model):
circuit_id = models.PositiveIntegerField(verbose_name=_("Circuit ID"), blank=True, null=True)
model = models.ForeignKey(Versiiplates, verbose_name=_("Model"))
date_created = models.DateField(blank=True, null=True, verbose_name=_("Date Created"), default=datetime.date.today())
manufacturer = models.ForeignKey(Manufacturer, null=True, blank=True, verbose_name="Производитель")
manufacturer_comments = models.TextField(max_length=2500, null=True, blank=True, verbose_name="Комментарии производителя")
keeper_type = models.ForeignKey(ContentType, blank=True, null=True, related_name="keeper_type")
keeper_id = models.PositiveIntegerField(blank=True, null=True)
keeper = generic.GenericForeignKey('keeper_type', 'keeper_id')
status = models.PositiveIntegerField(verbose_name=_("Status"), choices=STATUS_TYPE, default=0)
status_history = models.ManyToManyField(Status, blank=True, null=True)
status_comment = models.TextField(max_length=2500, blank=True, null=True, verbose_name="Комментарий")
def __unicode__(self):
return u"%s #%d" % (self.model, self.circuit_id)
class Meta:
verbose_name = _("Circuit")
verbose_name_plural = _("Circuits")
和它的 AdminModel:
class CircuitAdmin(admin.ModelAdmin):
fieldsets = [
(None, {'fields': ['circuit_id', 'model', 'date_created']}),
(_("Manufacturer"), {'fields':['manufacturer', 'manufacturer_comments']}),
(_("Status"), {'fields': ['status', 'status_comment']})
]
list_display = ('circuit_id', 'model', 'date_created', 'keeper', 'status')
search_fields = ('circuit_id', )
list_filter = ('model', 'status')
related_lookup_fields = {
'generic': [['keeper_type', 'keeper_id']]
}
但是在管理员中我的 GenericForeignKey 仍然没有小部件。为什么在grapelli 的使用示例中有两个GenericForeignKey 字段?