在django中,当我试图查看我的[Post.objects.all()]
其结果Post:Post Object
而不是Post: title
。 enter image description here模型对象是反射对象而不是标题
这里是我的models.py
from django.db import models
# Create your models here.
class Post(models.Model):
post_title=models.CharField(max_length=50,blank=False)
post_content=models.TextField()
creation_date=models.DateTimeField(auto_now=False,auto_now_add=True)
lastDate_modified=models.DateTimeField(auto_now=True,auto_now_add=False)
def __str__(self):
return self.post_title
和输出>>> Post.objects.all() [<Post: Post object>, <Post: Post object>]
您需要提供更多的co de,它不可能回答这个问题 – techarch
看起来你想要覆盖'__repr__'而不是'__str__':https://docs.python.org/3.5/library/functions.html#repr –