[英]Can someone help me fix this? first time trying this. AttributeError: type object 'Post' has no attribute 'published'
这是在 view.py 中:
class PostListView(ListView):
queryset = Post.published.all()
context_object_name = 'posts'
paginate_by = 4
template_name = 'blog/post/list.html'
这是models.py中的model
class PublishedManager(models.Manager):
def get_queryset(self):
return super(PublishedManager, self).get_queryset().filter(status='published')
您已创建管理器,但未将管理器分配给 model 作为名为“已发布”的属性:
class Post(models.Model):
# other fields
published = PublishedManager()
有关更多详细信息和注意事项,请参阅文档。
当您引用 Post.published.all() 时,这意味着您对某些字段具有自定义model 管理器。
您确定您创建了自定义管理器吗? 也许你的意思是类似的。
Post.objects.filter(for_example_status="pusblished")
请提供有关模型结构的更多详细信息
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.