Hey I am currently going through the Django tutorials and I am trying to display all of my Post objects in the python shell using
from blog.models import Post
Post.objects.all()
my model is
from django.db import models
from django.utils import timezone
from django.contrib.auth.models import User
# Create your models here.
class Post(models.Model):
title = models.CharField(max_length=200)
contents = models.TextField()
date_posted = models.DateTimeField(default=timezone.now)
author = models.ForeignKey(User,on_delete=models.CASCADE)
def __str__(self):
return self.title
It should display
`
[<Post: Title>, <Post: Title2>]
instead of
[<Post: Post object>, <Post: Post object>]
It just says “Post object” instead of the title. What is the reason why? I have been following the tutorial exactly and can’t understand why it displays it like that. It’s hard to organize all of the posts when it says “Post object” for all of them.
I am using the latest version of python and django.