0
0
mirror of https://github.com/django/django.git synced 2024-12-01 15:42:04 +01:00

Clarified Concat example in docs.

This commit is contained in:
Mathieu Hinderyckx 2017-08-13 15:24:14 +02:00 committed by Tim Graham
parent 71d39571f4
commit cf5740fbc8

View File

@ -88,8 +88,9 @@ Usage examples::
Accepts a list of at least two text fields or expressions and returns the Accepts a list of at least two text fields or expressions and returns the
concatenated text. Each argument must be of a text or char type. If you want concatenated text. Each argument must be of a text or char type. If you want
to concatenate a ``TextField()`` with a ``CharField()``, then be sure to tell to concatenate a ``TextField()`` with a ``CharField()``, then be sure to tell
Django that the ``output_field`` should be a ``TextField()``. This is also Django that the ``output_field`` should be a ``TextField()``. Specifying an
required when concatenating a ``Value`` as in the example below. ``output_field`` is also required when concatenating a ``Value`` as in the
example below.
This function will never have a null result. On backends where a null argument This function will never have a null result. On backends where a null argument
results in the entire expression being null, Django will ensure that each null results in the entire expression being null, Django will ensure that each null
@ -102,8 +103,11 @@ Usage example::
>>> from django.db.models.functions import Concat >>> from django.db.models.functions import Concat
>>> Author.objects.create(name='Margaret Smith', goes_by='Maggie') >>> Author.objects.create(name='Margaret Smith', goes_by='Maggie')
>>> author = Author.objects.annotate( >>> author = Author.objects.annotate(
... screen_name=Concat('name', V(' ('), 'goes_by', V(')'), ... screen_name=Concat(
... output_field=CharField())).get() ... 'name', V(' ('), 'goes_by', V(')'),
... output_field=CharField()
... )
... ).get()
>>> print(author.screen_name) >>> print(author.screen_name)
Margaret Smith (Maggie) Margaret Smith (Maggie)