[Answered ]-Filter Django queryset

2👍

Solution

Your client field in the ClientsGroup model is incorrect. It should be

clients = models.ManyToManyField("Client")

not

clients = models.ManyToMany("Client")

When you fix that, I think it should work. Double check that your models do actually have objects in them and that they link to eachother.

Futher Debugging

If it still doesn’t work after changing the field name, try splitting up your query to debug. For example you could the query into two seperate queries

target_client = Client.objects.get(user=logged_in_user)
list_of_events = Event.objects.filter(clients_group__clients=target_client)

From here you can figure out which queries are working and which aren’t.

Leave a comment