Fixed #24629 -- Unified Transform and Expression APIs

This commit is contained in:
Josh Smeaton 2015-08-03 12:30:06 +10:00
parent 8dc3ba5ceb
commit 534aaf56f4
15 changed files with 522 additions and 377 deletions

View file

@ -42,12 +42,17 @@ register lookups on itself. The two prominent examples are
A mixin that implements the lookup API on a class.
.. classmethod:: register_lookup(lookup)
.. classmethod:: register_lookup(lookup, lookup_name=None)
Registers a new lookup in the class. For example
``DateField.register_lookup(YearExact)`` will register ``YearExact``
lookup on ``DateField``. It overrides a lookup that already exists with
the same name.
the same name. ``lookup_name`` will be used for this lookup if
provided, otherwise ``lookup.lookup_name`` will be used.
.. versionchanged:: 1.9
The ``lookup_name`` parameter was added.
.. method:: get_lookup(lookup_name)
@ -125,7 +130,14 @@ Transform reference
``<expression>__<transformation>`` (e.g. ``date__year``).
This class follows the :ref:`Query Expression API <query-expression>`, which
implies that you can use ``<expression>__<transform1>__<transform2>``.
implies that you can use ``<expression>__<transform1>__<transform2>``. It's
a specialized :ref:`Func() expression <func-expressions>` that only accepts
one argument. It can also be used on the right hand side of a filter or
directly as an annotation.
.. versionchanged:: 1.9
``Transform`` is now a subclass of ``Func``.
.. attribute:: bilateral
@ -152,18 +164,6 @@ Transform reference
:class:`~django.db.models.Field` instance. By default is the same as
its ``lhs.output_field``.
.. method:: as_sql
To be overridden; raises :exc:`NotImplementedError`.
.. method:: get_lookup(lookup_name)
Same as :meth:`~lookups.RegisterLookupMixin.get_lookup()`.
.. method:: get_transform(transform_name)
Same as :meth:`~lookups.RegisterLookupMixin.get_transform()`.
Lookup reference
~~~~~~~~~~~~~~~~