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@…, Carsten Fuchs||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 6 years ago by
|Owner:||changed from nobody to rasca|
|Version:||1.2 → SVN|