Skip to main content
Django Code Completion Medium +20 XP

Model String Representation

Complete to give the model a human-readable name.

DjangoFill in the blank
class Product(models.Model):
    name = models.CharField(max_length=100)
    def _____(self): return self.name

Type the missing code

Show answer and explanation

Answer: __str__

__str__ defines how the model displays as a string in admin, shell, and templates. Always define it for better DX.

Hint: Which dunder method defines string representation?

What this challenge tests

Code Completion in Django: models, dunder-methods.

Related challenges