File: annotations.rst

package info (click to toggle)
python-django-postgres-extra 2.0.9-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,096 kB
  • sloc: python: 9,057; makefile: 17; sh: 7; sql: 1
file content (27 lines) | stat: -rw-r--r-- 696 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
.. include:: ./snippets/postgres_doc_links.rst
.. include:: ./snippets/manager_model_warning.rst

.. _annotations_page:

Annotations
===========


Renaming annotations
--------------------

Django does not allow you to create an annotation that conflicts with a field on the model. :meth:`psqlextra.query.QuerySet.rename_annotation` makes it possible to do just that.

.. code-block:: python

   from psqlextra.models import PostgresModel
   from django.db.models import Upper

   class MyModel(PostgresModel):
        name = models.TextField()

   MyModel.objects.annotate(name=Upper('name'))

   # OR

   MyModel.objects.annotate(name_upper=Upper('name')).rename_annotations(name='name_upper')