Re: This should be taken in consideration : ordering variable in ListView Class

37 views
Skip to first unread message

Adam Johnson

unread,
Jan 4, 2021, 5:58:09 PM1/4/21
to django-d...@googlegroups.com
Hi

Please don't use this post for support. See https://docs.djangoproject.com/en/3.1/faq/help/

Thanks,

Adam

On Sun, 3 Jan 2021 at 16:38, AMINE ART <amine.gha...@gmail.com> wrote:
Can get you every post if you fill it
I comment it to get only the user posts

class UserPostsListView(ListView):
model = Post
template_name = 'posts/pages/index.html'
context_object_name = 'posts'
#That line can ruine everything
#ordering = ['-date_posted']
paginate_by = 1

def get_query_set(self):
    username = self.kwargs.get('username')
   user = get_object_or_404( User.objects.get(User, username=username) )
   return Post.objects.filter(author=user).ordered_by('-date_posted')

--
You received this message because you are subscribed to the Google Groups "Django developers (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-develop...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-developers/4ab6c581-360a-4588-b1df-58398168afb6n%40googlegroups.com.


--
Adam
Reply all
Reply to author
Forward
0 new messages