سؤال

I am creating a website using django, I have a table called articles, whenever I create any new record it is showing correctly in the database (Postgres) and in the details page of django admin, but in the listing it is being displayed as: Article object. Any Idea?

Thanks

هل كانت مفيدة؟

المحلول

You need to implement the unicode() method in the Article model class.

For example:

class Article(models.Model):

    name = models.Charfield()

    def __unicode__(self):
        return self.name

نصائح أخرى

Define a __unicode__ method for your model.

I figured it out. I forgot to add the below in my model:

def __unicode__(self):
        return self.title
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top