mirror of
https://github.com/django/django.git
synced 2025-10-05 00:00:37 +00:00
Fixed #22207 -- Added support for GenericRelation reverse lookups
GenericRelation now supports an optional related_query_name argument. Setting related_query_name adds a relation from the related object back to the content type for filtering, ordering and other query operations. Thanks to Loic Bistuer for spotting a couple of important issues in his review.
This commit is contained in:
parent
c627da0ccc
commit
b77f26313c
9 changed files with 71 additions and 27 deletions
|
@ -449,9 +449,7 @@ class Options(object):
|
|||
for f, model in self.get_fields_with_model():
|
||||
cache[f.name] = cache[f.attname] = (f, model, True, False)
|
||||
for f in self.virtual_fields:
|
||||
if hasattr(f, 'related'):
|
||||
cache[f.name] = cache[f.attname] = (
|
||||
f.related, None if f.model == self.model else f.model, True, False)
|
||||
cache[f.name] = (f, None if f.model == self.model else f.model, True, False)
|
||||
if apps.ready:
|
||||
self._name_map = cache
|
||||
return cache
|
||||
|
@ -530,8 +528,9 @@ class Options(object):
|
|||
proxy_cache = cache.copy()
|
||||
for klass in self.apps.get_models(include_auto_created=True):
|
||||
if not klass._meta.swapped:
|
||||
for f in klass._meta.local_fields:
|
||||
if f.rel and not isinstance(f.rel.to, six.string_types) and f.generate_reverse_relation:
|
||||
for f in klass._meta.local_fields + klass._meta.virtual_fields:
|
||||
if (hasattr(f, 'rel') and f.rel and not isinstance(f.rel.to, six.string_types)
|
||||
and f.generate_reverse_relation):
|
||||
if self == f.rel.to._meta:
|
||||
cache[f.related] = None
|
||||
proxy_cache[f.related] = None
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue