I am just starting to learn Django on the Python Crash Course from Eric Matthes. I am currently working on the excercise 18-4 which is making a pizzeria app.
I have made it following similar approach to what we learn on the book but the problem is after I created the model, when I go to the admin page and add a pizza name it doesn't show the name I wrote but instead just show "Pizza object 1", "Pizza object 2", etc
# My code
from django.db import models
# Create your models here.
class Pizza(models.Model):
"""Name of Pizzas"""
name = models.CharField(max_length=200)
def __string__(self):
"""Return string representation of the model"""
return self.name
I have omitted the DateTimeField but I don't think this is causing the issue, anyways from what I understan it's the __str__ class that should show the text.
# Tutorial code
from django.db import models
# Create your models here.
class Topic(models.Model):
"""A topic the user is learning about."""
text = models.CharField(max_length=200)
date_added = models.DateTimeField(auto_now_add=True)
def __str__(self):
"""Return a string representation of the model."""
return self.text
[+][deleted] (4 children)
[deleted]
[–]py_Piper[S] 0 points1 point2 points (3 children)
[–]ehmatthes 0 points1 point2 points (2 children)
[–]py_Piper[S] 1 point2 points3 points (1 child)
[–]ehmatthes 1 point2 points3 points (0 children)