diff options
| author | InvalidInterrupt <InvalidInterrupt@users.noreply.github.com> | 2016-08-18 15:42:11 -0700 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2016-12-07 17:50:51 -0500 |
| commit | 98359109eb0ed68a5821476bcd797455723aaaba (patch) | |
| tree | f54f4fd3acffe5551873b4d00faab512a9e583d5 /django/db/models/sql | |
| parent | b5f0b3478dfcf0335f8ac2038d59f54b4a05f2a0 (diff) | |
Fixed #17002 -- Allowed using a ManyToManyField through model that inherits another.
Diffstat (limited to 'django/db/models/sql')
| -rw-r--r-- | django/db/models/sql/query.py | 22 |
1 files changed, 6 insertions, 16 deletions
diff --git a/django/db/models/sql/query.py b/django/db/models/sql/query.py index a1e476c592..5eea5ad939 100644 --- a/django/db/models/sql/query.py +++ b/django/db/models/sql/query.py @@ -19,7 +19,7 @@ from django.db.models.constants import LOOKUP_SEP from django.db.models.expressions import Col, Ref from django.db.models.fields.related_lookups import MultiColSource from django.db.models.query_utils import ( - PathInfo, Q, check_rel_lookup_compatibility, refs_expression, + Q, check_rel_lookup_compatibility, refs_expression, ) from django.db.models.sql.constants import ( INNER, LOUTER, ORDER_DIR, ORDER_PATTERN, QUERY_TERMS, SINGLE, @@ -1342,21 +1342,11 @@ class Query(object): # field lives in parent, but we are currently in one of its # children) if model is not opts.model: - # The field lives on a base class of the current model. - # Skip the chain of proxy to the concrete proxied model - proxied_model = opts.concrete_model - - for int_model in opts.get_base_chain(model): - if int_model is proxied_model: - opts = int_model._meta - else: - final_field = opts.parents[int_model] - targets = (final_field.remote_field.get_related_field(),) - opts = int_model._meta - path.append(PathInfo(final_field.model._meta, opts, targets, final_field, False, True)) - cur_names_with_path[1].append( - PathInfo(final_field.model._meta, opts, targets, final_field, False, True) - ) + path_to_parent = opts.get_path_to_parent(model) + if path_to_parent: + path.extend(path_to_parent) + cur_names_with_path[1].extend(path_to_parent) + opts = path_to_parent[-1].to_opts if hasattr(field, 'get_path_info'): pathinfos = field.get_path_info() if not allow_many: |
