简体   繁体   中英

Can someone help me fix this? first time trying this. AttributeError: type object 'Post' has no attribute 'published'

This is in view.py:

class PostListView(ListView):
    queryset = Post.published.all()
    context_object_name = 'posts'
    paginate_by = 4
    template_name = 'blog/post/list.html'

this is the model in models.py

class PublishedManager(models.Manager):
    def get_queryset(self):
        return super(PublishedManager, self).get_queryset().filter(status='published')

You have created the manager, but not assigned the manager to the model as an attribute called 'published':

class Post(models.Model):
    # other fields
    published = PublishedManager()

See the documentation for further details and caveats.

When you refer Post.published.all() it means you have custom model manager for some field.

Are you sure you have custom manager created? Maybe you meant something like.

Post.objects.filter(for_example_status="pusblished")

Please,provide more details on models structure

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM