Reputation: 127
I've managed to make a simple blog app in django using some tutorials, however there's one thing I'd like to change: when viewing all posts using admin panel, all of them are named Post object. Is there a way to fix it so there's a title of a post instead of Post object?
Post model:
class Post(models.Model):
title = models.CharField(max_length=255)
datetime = models.DateTimeField(u'Date of publishing')
content = models.TextField(max_length=10000)
Upvotes: 1
Views: 124
Reputation: 5172
You need to implement a __unicode__
method on your model.
class Post(models.Model):
title = models.CharField(max_length=255)
datetime = models.DateTimeField(u'Date of publishing')
content = models.TextField(max_length=10000)
def __unicode__(self):
return self.title
Note that in case you're using Python 3, you should use __str__
instead.
Docs on this: link
Upvotes: 6