When using a ManyToMany in list_filter, results may apper more than once
|Reported by:||rasca||Owned by:||rasca|
|Severity:||Keywords:||admin change_list list_filter manytomany|
|Cc:||rasca7@…, CarstenF||Triage Stage:||Ready for checkin|
|Has patch:||yes||Needs documentation:||no|
|Needs tests:||no||Patch needs improvement:||yes|
Suppose you have a ManyToMany relationship between models A and B through a model C.
If you have more than one entry of C relating the same A and B instances, and in the admin in the model A change_list you are list_filtering by the relationship with B, and filter by the B instance that has more than 1 relation to the same A instance, the A instance appears as many times as there are relationships in the list, when it should appear only once.
I'm not sure where to add the .distinct() in admin.views.ChangeList.get_query_set(). We could add it when it returns the final queryset but I'm not sure if that's the most efficient way to do it. We could check to see if it's needed.
There's also another .distinct() before but that one only applies to the search field (in case it's needed). Maybe combine these two?
Change History (16)
comment:1 Changed 5 years ago by rasca
- Has patch set
- Needs documentation unset
- Needs tests unset
- Owner changed from nobody to rasca
- Patch needs improvement unset
- Version changed from 1.2 to SVN