'why def __str__(self): return self.title is not changing the object's title in the database?

I created a database by django but when changing the object name using

  def __str__(self):
     return self.title

does not change. Here's the code:

def __str__(self):
     return self.title


class Class(models.Model):

     Status = (
               ('doing', 'doing'),
               ('done', 'completed')
     )

     title = models.CharField(max_length=255)
     description = models.TextField()
     done = models.CharField(
             max_length=6,
             choices=Status


created_at = models.DateTimeField(auto_now_add=True)
updated_at = models.DateTimeField(auto_now=True) 


Solution 1:[1]

Your model should be:

class Class(models.Model):

     Status = (
               ('doing', 'doing'),
               ('done', 'completed')
     )

     title = models.CharField(max_length=255)
     description = models.TextField()
     done = models.CharField(
             max_length=6,
             choices=Status


created_at = models.DateTimeField(auto_now_add=True)
updated_at = models.DateTimeField(auto_now=True) 

def __str__(self):
     return self.title

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Rajat Jog