queryset values(), values_list(), distinct() documented; defer(), only() allowed (but not yet supported)
parent
cf42a8111b
commit
b4aeae417e
62
DOCS.rst
62
DOCS.rst
|
|
@ -1,5 +1,5 @@
|
||||||
.. contents:: Table of Contents
|
.. contents:: Table of Contents
|
||||||
:depth: 1
|
:depth: 1
|
||||||
|
|
||||||
Installation / Testing
|
Installation / Testing
|
||||||
======================
|
======================
|
||||||
|
|
@ -173,18 +173,33 @@ ManyToManyField, ForeignKey, OneToOneField
|
||||||
<ModelB: id 2, field1 (CharField), field2 (CharField)>,
|
<ModelB: id 2, field1 (CharField), field2 (CharField)>,
|
||||||
<ModelC: id 3, field1 (CharField), field2 (CharField), field3 (CharField)> ]
|
<ModelC: id 3, field1 (CharField), field2 (CharField), field3 (CharField)> ]
|
||||||
|
|
||||||
annotate(), aggregate() & extra()
|
More Queryset Methods
|
||||||
---------------------------------
|
---------------------
|
||||||
|
|
||||||
+ ``annotate()`` and ``aggregate()`` work just as usual, with the
|
+ ``annotate()`` and ``aggregate()`` work just as usual, with the
|
||||||
addition that the ``ModelX___field`` syntax can be used for the
|
addition that the ``ModelX___field`` syntax can be used for the
|
||||||
keyword arguments (but not for the non-keyword arguments).
|
keyword arguments (but not for the non-keyword arguments).
|
||||||
|
|
||||||
+ ``extra()`` by default works exactly like the vanilla version,
|
+ ``distinct()`` works as expected. It only regards the fields of
|
||||||
with the resulting queryset not being polymorphic. There is
|
the base class, but this should never make a difference.
|
||||||
experimental support for polymorphic queries with extra() via
|
|
||||||
the keyword argument ``polymorphic=True`` (then only the
|
+ ``select_related()`` works just as usual, but it can not (yet) be used
|
||||||
``where`` and ``order_by`` arguments of extra() should be used).
|
to select relations in derived models
|
||||||
|
(like ``ModelA.objects.select_related('ModelC___fieldxy')`` )
|
||||||
|
|
||||||
|
+ ``extra()`` by default works exactly like the original version,
|
||||||
|
with the resulting queryset not being polymorphic. There is
|
||||||
|
experimental support for a polymorphic extra() via the keyword
|
||||||
|
argument ``polymorphic=True`` (only the ``where`` and
|
||||||
|
``order_by`` arguments of extra() should be used then).
|
||||||
|
|
||||||
|
+ ``values()`` & ``values_list()`` currently do not return polymorphic
|
||||||
|
results. This may change in the future however. If you want to use these
|
||||||
|
methods now, it's best if you use ``Model.base_objects.values...`` as
|
||||||
|
this is guaranteed to not change.
|
||||||
|
|
||||||
|
+ ``defer()`` and ``only()`` are not yet supported (support will be added
|
||||||
|
in the future).
|
||||||
|
|
||||||
Non-Polymorphic Queries
|
Non-Polymorphic Queries
|
||||||
-----------------------
|
-----------------------
|
||||||
|
|
@ -364,26 +379,11 @@ So it seems this optimization can be done at any later time
|
||||||
(like when it's needed).
|
(like when it's needed).
|
||||||
|
|
||||||
|
|
||||||
Unsupported Methods, Restrictions & Caveats
|
|
||||||
===========================================
|
|
||||||
|
|
||||||
Currently Unsupported Queryset Methods
|
|
||||||
--------------------------------------
|
|
||||||
|
|
||||||
+ ``defer()`` and ``only()``: Full support, including slight polymorphism
|
|
||||||
enhancements, seems to be straighforward (depends on '_get_real_instances').
|
|
||||||
|
|
||||||
+ ``select_related()`` works just as usual, but it can not (yet) be used
|
|
||||||
to select relations in derived models
|
|
||||||
(like ``ModelA.objects.select_related('ModelC___fieldxy')`` )
|
|
||||||
|
|
||||||
+ ``distinct()`` needs more thought and investigation
|
|
||||||
|
|
||||||
+ ``values()`` & ``values_list()``: Implementation seems to be mostly straighforward
|
|
||||||
|
|
||||||
|
|
||||||
Restrictions & Caveats
|
Restrictions & Caveats
|
||||||
----------------------
|
======================
|
||||||
|
|
||||||
|
* The queryset methods ``values()``, ``values_list()``, ``select_related()``,
|
||||||
|
``defer()`` and ``only()`` are not yet fully supported (see above)
|
||||||
|
|
||||||
* Django 1.1 only - the names of polymorphic models must be unique
|
* Django 1.1 only - the names of polymorphic models must be unique
|
||||||
in the whole project, even if they are in two different apps.
|
in the whole project, even if they are in two different apps.
|
||||||
|
|
|
||||||
|
|
@ -131,10 +131,6 @@ class PolymorphicQuerySet(QuerySet):
|
||||||
if 'polymorphic' in kwargs: kwargs.pop('polymorphic')
|
if 'polymorphic' in kwargs: kwargs.pop('polymorphic')
|
||||||
return super(PolymorphicQuerySet, self).extra(*args, **kwargs)
|
return super(PolymorphicQuerySet, self).extra(*args, **kwargs)
|
||||||
|
|
||||||
# these queryset functions are not yet supported
|
|
||||||
def defer(self, *args, **kwargs): raise NotImplementedError
|
|
||||||
def only(self, *args, **kwargs): raise NotImplementedError
|
|
||||||
|
|
||||||
def _get_real_instances(self, base_result_objects):
|
def _get_real_instances(self, base_result_objects):
|
||||||
"""
|
"""
|
||||||
Polymorphic object loader
|
Polymorphic object loader
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue