Opened 11 years ago
Last modified 11 years ago
#23467 closed Bug
Inconsistent behavior when filtering by inherited models when using a proxy model — at Initial Version
| Reported by: | Luis A. Arce | Owned by: | nobody |
|---|---|---|---|
| Component: | Database layer (models, ORM) | Version: | 1.6 |
| Severity: | Normal | Keywords: | inherit, proxy, model, queryset, filter |
| Cc: | Triage Stage: | Unreviewed | |
| Has patch: | no | Needs documentation: | no |
| Needs tests: | no | Patch needs improvement: | no |
| Easy pickings: | no | UI/UX: | no |
Description
Having the following scenario:
import django.db.models as db_models
class ParentModel(db_models.Model):
pass
class ChildModel(ParentModel):
pass
class ParentProxyModel(ParentModel):
pass
I can filter the ParentModel in terms of existing inheriting children, but not ParentProxyModel. An example:
Python 2.7.5 (default, Jun 25 2014, 10:19:55)
[GCC 4.8.2 20131212 (Red Hat 4.8.2-7)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
(InteractiveConsole)
>>> a = ParentModel.objects.create()
>>> b = ChildModel.objects.create()
>>> ParentModel.objects.filter(childmodel=None)
[<ParentModel: ParentModel object>]
>>> ParentProxyModel.objects.filter(childmodel=None)
Traceback (most recent call last):
File "<console>", line 1, in <module>
File "/home/ajaest/Code/pfc/src/.env/lib/python2.7/site-packages/django/db/models/manager.py", line 163, in filter
return self.get_queryset().filter(*args, **kwargs)
File "/home/ajaest/Code/pfc/src/.env/lib/python2.7/site-packages/django/db/models/query.py", line 590, in filter
return self._filter_or_exclude(False, *args, **kwargs)
File "/home/ajaest/Code/pfc/src/.env/lib/python2.7/site-packages/django/db/models/query.py", line 608, in _filter_or_exclude
clone.query.add_q(Q(*args, **kwargs))
File "/home/ajaest/Code/pfc/src/.env/lib/python2.7/site-packages/django/db/models/sql/query.py", line 1198, in add_q
clause = self._add_q(where_part, used_aliases)
File "/home/ajaest/Code/pfc/src/.env/lib/python2.7/site-packages/django/db/models/sql/query.py", line 1234, in _add_q
current_negated=current_negated)
File "/home/ajaest/Code/pfc/src/.env/lib/python2.7/site-packages/django/db/models/sql/query.py", line 1100, in build_filter
allow_explicit_fk=True)
File "/home/ajaest/Code/pfc/src/.env/lib/python2.7/site-packages/django/db/models/sql/query.py", line 1357, in setup_joins
names, opts, allow_many, allow_explicit_fk)
File "/home/ajaest/Code/pfc/src/.env/lib/python2.7/site-packages/django/db/models/sql/query.py", line 1277, in names_to_path
"Choices are: %s" % (name, ", ".join(available)))
FieldError: Cannot resolve keyword 'childmodel' into field. Choices are: id, parentmodel_ptr
>>>
Note:
See TracTickets
for help on using tickets.