Ticket #24656: django_patch_24656.diff

File django_patch_24656.diff, 2.6 KB (added by Nicolas Noé, 10 years ago)
  • AUTHORS

    diff --git a/AUTHORS b/AUTHORS
    index ebf5c49..f6f32a0 100644
    a b answer newbie questions, and generally made Django that much better:  
    522522    Niclas Olofsson <n@niclasolofsson.se>
    523523    Nicola Larosa <nico@teknico.net>
    524524    Nicolas Lara <nicolaslara@gmail.com>
     525    Nicolas Noé <nicolas@niconoe.eu>
    525526    Niran Babalola <niran@niran.org>
    526527    Nis Jørgensen <nis@superlativ.dk>
    527528    Nowell Strite <http://nowell.strite.org/>
  • docs/ref/models/expressions.txt

    diff --git a/docs/ref/models/expressions.txt b/docs/ref/models/expressions.txt
    index b180327..8055744 100644
    a b Some examples  
    2626
    2727.. code-block:: python
    2828
     29    from django.db.models import F, Count
     30    from django.db.models.functions import Length
     31
    2932    # Find companies that have more employees than chairs.
    3033    Company.objects.filter(num_employees__gt=F('num_chairs'))
    3134
    Some examples  
    6265Built-in Expressions
    6366====================
    6467
     68.. note::
     69
     70    Technically, these expressions are defined in
     71    ``django.db.models.expressions`` and ``django.db.models.aggregate``, but for
     72    convenience they're imported into :mod:`django.db.models`.
     73
    6574``F()`` expressions
    6675-------------------
    6776
    into memory and manipulated it using familiar Python operators, and then saved  
    8897the object back to the database. But instead we could also have done::
    8998
    9099    from django.db.models import F
     100
    91101    reporter = Reporters.objects.get(name='Tintin')
    92102    reporter.stories_filed = F('stories_filed') + 1
    93103    reporter.save()
    directly support ``output_field`` you will need to wrap the expression with  
    194204database functions like ``COALESCE`` and ``LOWER``, or aggregates like ``SUM``.
    195205They can be used directly::
    196206
     207    from django.db.models import Func, F
     208
    197209    queryset.annotate(field_lower=Func(F('field'), function='LOWER'))
    198210
    199211or they can be used to build a library of database functions::
    Creating your own aggregate is extremely easy. At a minimum, you need  
    314326to define ``function``, but you can also completely customize the
    315327SQL that is generated. Here's a brief example::
    316328
     329    from django.db.models import Aggregate
     330
    317331    class Count(Aggregate):
    318332        # supports COUNT(distinct field)
    319333        function = 'COUNT'
    to play nice with other query expressions::  
    577591        self.expressions = expressions
    578592
    579593Let's see how it works::
    580 
     594    >>> from django.db.models import F, Value, CharField
    581595    >>> qs = Company.objects.annotate(
    582596    ...    tagline=Coalesce([
    583597    ...        F('motto'),
Back to Top