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
In the Django admin I would if possibile, under the “Comments” page, see the __unicode__ of the content object, for example can be Product.
Something this:
All comments
Comment 1 – to a Product – Foo Bar (unicode of Product) – timestamp
Comment 2 – to a UserProfile – Foo Bar (unicode of UserProfile) – timestamp
etc.
Ideas for admin.py?
I suggest adding unicode method to Comment model:
If you are using standart ModelAdmin, then there is no need to change admin.py.