How to change the name of objects in Django admin?

What to do? I kept restarting my server but it still didn't work. This is the whole code snippet of my models.py:

from django.db import models

    class Blog(models.Model):
        title = models.CharField(max_length=50)
        pub_date = models.DateField(auto_now_add=True)
        # publication date
        image = models.ImageField(upload_to='images/')
        summary = models.CharField(max_length=200)
        body = models.TextField()

    def __str__(self):
        return self.title

But the names of each objects are still not changing: enter image description here


Solution 1:

Put the method inside the Blog Model as following:

models.py

from django.db import models


class Blog(models.Model):

    def __str__(self):
        return self.title


Solution 2:

Your def str(self) is not indented inside your model class. Make the changes and it will work.

class modelClass(models.Model):
    #your properties
        
    #below method should be indented 
    def __str__(self):
        return self.property

Solution 3:

Could you try below?

class Blog(models.Model):
    ........

    def __str__(self):
        return str(self.title)