0
class Comment(models.Model):
text = models.TextField()
timestamp = models.DateTimeField(auto_now_add = True)
content_type = models.ForeignKey(ContentType)
object_id = models.PositiveIntegerField()
content_object = generic.GenericForeignKey('content_type', 'object_id')
class Product(models.Model):
name = models.CharField(max_length = 40)
comments = generic.GenericRelation(Comment)
def __unicode__(self):
return self.name
在Django管理我想如果不可能性,“注释”页面下,看到的内容对象的__unicode__
,例如可以是产品。Django的GenericForeignKey在管理
东西这样的:
所有评论
注释1 - 一个产品 - 美孚酒吧(产品的统一) - 时间戳
评论2 - 为用户配置 - 美孚酒吧(unicode UserProfile) - 时间戳
等
想法admin.py?
感谢您的回复。如何在模型管理页面的字段中显示__unicode__方法? –
你的意思是使用list_display ?:'list_display('__ unicode __',)' – Pill
你摇滚!非常感谢你! –