Fix 1.6 regression when GenericRelation+ForeignKey path used as admin list_filter #1913

wants to merge 3 commits into


None yet
2 participants

As mentioned in trac #21428

Previously in 1.5 it was possible to have a model A with a GenericRelation field to a model B that had a ForeignKey to model C, and use the B__C path in A's admin list_filter.

In 1.6 this fails in django.contrib.admin.util.get_model_from_relation where the model on the wrong side of the relationship is returned, when the correct model is available via the parent_model attribute.


akaariai commented Nov 13, 2013

As said in #21428 a separate ticket is the way to go here.

I think I want to patch L428 of django/db/models/ and assign f directly of f.related to the cache there. This requires also changing the direction of GenericRelation.get_path_info(). A possible problem is that there might be already code out there that relies on the new way, if so some other way will need to be invented. Just fetching parent_model if that exists (as done in this PR) seems wrong - parent_model always exists for RelatedObject, so the elif isinstance(field, models.related.RelatedObject) branch will never get executed.

New ticket here:

As discussed I'm not really across how the internals of this work so I don't think I can help much more.


akaariai commented Nov 21, 2013

Fixed in 752d3d7

@akaariai akaariai closed this Nov 21, 2013

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment