Fixed applabel__ModelName___field looksups

Closes: #286
fix_request_path_info
Diederik van der Boor 2017-11-20 15:18:43 +01:00
parent 0367d5f3ee
commit 8f0932b71e
3 changed files with 15 additions and 1 deletions

View File

@ -20,6 +20,7 @@ Changes in git
* Using ``base_model`` on the polymorphic admins is no longer required, as this can be autodetected. * Using ``base_model`` on the polymorphic admins is no longer required, as this can be autodetected.
* Fixed manager errors for swappable models. * Fixed manager errors for swappable models.
* Fixed deleteText of ``|as_script_options`` template filter. * Fixed deleteText of ``|as_script_options`` template filter.
* Fixed ``.filter(applabel__ModelName___field=...)`` lookups.
* Improved ``polymorphic.utils.reset_polymorphic_ctype()`` to accept models in random ordering. * Improved ``polymorphic.utils.reset_polymorphic_ctype()`` to accept models in random ordering.
* Fix fieldsets handling in the admin (``declared_fieldsets`` is removed since Django 1.9) * Fix fieldsets handling in the admin (``declared_fieldsets`` is removed since Django 1.9)

View File

@ -7,6 +7,7 @@ from __future__ import absolute_import
import copy import copy
from functools import reduce from functools import reduce
from django.apps import apps
from django.contrib.contenttypes.models import ContentType from django.contrib.contenttypes.models import ContentType
from django.db import models from django.db import models
from django.db.models.fields.related import ForeignObjectRel, RelatedField from django.db.models.fields.related import ForeignObjectRel, RelatedField
@ -142,7 +143,7 @@ def translate_polymorphic_field_path(queryset_model, field_path):
if '__' in classname: if '__' in classname:
# the user has app label prepended to class name via __ => use Django's get_model function # the user has app label prepended to class name via __ => use Django's get_model function
appname, sep, classname = classname.partition('__') appname, sep, classname = classname.partition('__')
model = models.get_model(appname, classname) model = apps.get_model(appname, classname)
assert model, 'PolymorphicModel: model %s (in app %s) not found!' % (model.__name__, appname) assert model, 'PolymorphicModel: model %s (in app %s) not found!' % (model.__name__, appname)
if not issubclass(model, queryset_model): if not issubclass(model, queryset_model):
e = 'PolymorphicModel: queryset filter error: "' + model.__name__ + '" is not derived from "' + queryset_model.__name__ + '"' e = 'PolymorphicModel: queryset filter error: "' + model.__name__ + '" is not derived from "' + queryset_model.__name__ + '"'

View File

@ -566,6 +566,18 @@ class PolymorphicTests(TransactionTestCase):
ordered=False, ordered=False,
) )
def test_polymorphic_applabel___filter(self):
self.create_model2abcd()
assert Model2B._meta.app_label == 'tests'
objects = Model2A.objects.filter(Q(tests__Model2B___field2='B2') | Q(tests__Model2C___field3='C3'))
self.assertQuerysetEqual(
objects,
[Model2B, Model2C],
transform=lambda o: o.__class__,
ordered=False,
)
def test_query_filter_exclude_is_immutable(self): def test_query_filter_exclude_is_immutable(self):
# given # given
q_to_reuse = Q(Model2B___field2='something') q_to_reuse = Q(Model2B___field2='something')