这是在view.py中:
class PostListView(ListView):
queryset = Post.published.all()
context_object_name = 'posts'
paginate_by = 4
template_name = 'blog/post/list.html'
这是models.py中的模型
class PublishedManager(models.Manager):
def get_queryset(self):
return super(PublishedManager, self).get_queryset().filter(status='published')
发布于 2020-05-21 13:01:48
您已经创建了管理器,但没有将管理器作为名为“published”的属性分配给模型:
class Post(models.Model):
# other fields
published = PublishedManager()
有关详细信息和注意事项,请参阅the documentation。
发布于 2020-05-20 13:47:27
当你引用Post.published.all()的时候,它意味着你对某些字段有自定义的model manager。
是否确定已创建自定义管理器?也许你的意思是像这样。
Post.objects.filter(for_example_status="pusblished")
请提供更多有关模型结构的详细信息
https://stackoverflow.com/questions/61914548
复制相似问题