Answer the question
In order to leave comments, you need to log in
Answer the question
In order to leave comments, you need to log in
I don't understand what you want to achieve with this distinction. Number of posts per user?
If yes, and the posts_count method belongs to the User model, then:
If the general solution is for a specific user:
user = ... # Откуда-то у тебя есть юзер
Post.objects.filter(user=user).count()
Post.objects.values("user").annotate(cnt=Count("*")).order_by("-cnt")
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question