Showing the car names

If you remember in the previous chapter, we looked at the __str__ method on a model class. I also said that Django uses this method wherever it needs to display a string representation of the model. Well, that's exactly what the Django admin does in the list view for the Car model: it displays the string representation for it. Let's make the list more user friendly by changing the string representation to something that the user can understand. In the frontend/models.py file, add this __str__ method to the Car model class:

def __str__(self):
    return self.name

Let's see what the list of Car objects looks now:

Showing the car names

That's a much better ...

Get Django Project Blueprints now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.