簡體   English   中英

有人可以幫我解決這個問題嗎? 第一次嘗試這個。 AttributeError:類型 object 'Post' 沒有屬性 'published'

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM