【发布时间】:2023-03-24 11:40:02
【问题描述】:
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__,例如可以是产品。
这样的:
所有 cmets
评论 1 - 对产品 - Foo Bar(产品的unicode) - 时间戳
评论 2 - 到 UserProfile - Foo Bar (unicode of UserProfile) - 时间戳
等等
admin.py 的想法?
【问题讨论】:
标签: python django django-admin