Skip to content
Justice Tech School

Model Methods

Add methods and __str__.

Example
class Post(models.Model):
    title = models.CharField(max_length=100)

    def __str__(self):
        return self.title

    def short(self):
        return self.title[:10]

Exercise

Readable name.

def (self):

Quiz Test

What does __str__ control?

These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.