Skip to content
Advertisement

django Count show different value after search

I simulate Instagram app.

I have Followers, Actions models.

Each action is done on a “follower”.

Many actions can point to one follower.

JavaScript

Admin panel:

JavaScript

I then override the get_queryset for followers:

JavaScript

I get really strange results in the admin panel: no search in panel

USERNAME : lior___shahar

BEEN FOLLOWED COUNT:5

FOLLOW BACK COUNT:5

This is the True VALUE in actions: Value in action

But once I do SEARCH in FOLLOWERS for the username: After Search

USERNAME : lior___shahar

BEEN FOLLOWED COUNT:320

FOLLOW BACK COUNT:320

I don’t get what is wrong.

Advertisement

Answer

Try adding distinct=True to the count annotation.

JavaScript
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement