Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
D
django
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
django
Commits
37682368
Kaydet (Commit)
37682368
authored
Nis 24, 2015
tarafından
Nicolas Noé
Kaydeden (comit)
Tim Graham
Nis 24, 2015
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Fixed #24656 -- Added missing imports to query expressions doc.
üst
ad31bc05
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
18 additions
and
0 deletions
+18
-0
AUTHORS
AUTHORS
+1
-0
expressions.txt
docs/ref/models/expressions.txt
+17
-0
No files found.
AUTHORS
Dosyayı görüntüle @
37682368
...
@@ -522,6 +522,7 @@ answer newbie questions, and generally made Django that much better:
...
@@ -522,6 +522,7 @@ answer newbie questions, and generally made Django that much better:
Niclas Olofsson <n@niclasolofsson.se>
Niclas Olofsson <n@niclasolofsson.se>
Nicola Larosa <nico@teknico.net>
Nicola Larosa <nico@teknico.net>
Nicolas Lara <nicolaslara@gmail.com>
Nicolas Lara <nicolaslara@gmail.com>
Nicolas Noé <nicolas@niconoe.eu>
Niran Babalola <niran@niran.org>
Niran Babalola <niran@niran.org>
Nis Jørgensen <nis@superlativ.dk>
Nis Jørgensen <nis@superlativ.dk>
Nowell Strite <http://nowell.strite.org/>
Nowell Strite <http://nowell.strite.org/>
...
...
docs/ref/models/expressions.txt
Dosyayı görüntüle @
37682368
...
@@ -26,6 +26,9 @@ Some examples
...
@@ -26,6 +26,9 @@ Some examples
.. code-block:: python
.. code-block:: python
from django.db.models import F, Count
from django.db.models.functions import Length
# Find companies that have more employees than chairs.
# Find companies that have more employees than chairs.
Company.objects.filter(num_employees__gt=F('num_chairs'))
Company.objects.filter(num_employees__gt=F('num_chairs'))
...
@@ -62,6 +65,12 @@ Some examples
...
@@ -62,6 +65,12 @@ Some examples
Built-in Expressions
Built-in Expressions
====================
====================
.. note::
These expressions are defined in ``django.db.models.expressions`` and
``django.db.models.aggregates``, but for convenience they're available and
usually imported from :mod:`django.db.models`.
``F()`` expressions
``F()`` expressions
-------------------
-------------------
...
@@ -88,6 +97,7 @@ into memory and manipulated it using familiar Python operators, and then saved
...
@@ -88,6 +97,7 @@ into memory and manipulated it using familiar Python operators, and then saved
the object back to the database. But instead we could also have done::
the object back to the database. But instead we could also have done::
from django.db.models import F
from django.db.models import F
reporter = Reporters.objects.get(name='Tintin')
reporter = Reporters.objects.get(name='Tintin')
reporter.stories_filed = F('stories_filed') + 1
reporter.stories_filed = F('stories_filed') + 1
reporter.save()
reporter.save()
...
@@ -194,6 +204,8 @@ directly support ``output_field`` you will need to wrap the expression with
...
@@ -194,6 +204,8 @@ directly support ``output_field`` you will need to wrap the expression with
database functions like ``COALESCE`` and ``LOWER``, or aggregates like ``SUM``.
database functions like ``COALESCE`` and ``LOWER``, or aggregates like ``SUM``.
They can be used directly::
They can be used directly::
from django.db.models import Func, F
queryset.annotate(field_lower=Func(F('field'), function='LOWER'))
queryset.annotate(field_lower=Func(F('field'), function='LOWER'))
or they can be used to build a library of database functions::
or they can be used to build a library of database functions::
...
@@ -259,6 +271,8 @@ like ``Sum()`` and ``Count()``, inherit from ``Aggregate()``.
...
@@ -259,6 +271,8 @@ like ``Sum()`` and ``Count()``, inherit from ``Aggregate()``.
Since ``Aggregate``\s are expressions and wrap expressions, you can represent
Since ``Aggregate``\s are expressions and wrap expressions, you can represent
some complex computations::
some complex computations::
from django.db.models import Count
Company.objects.annotate(
Company.objects.annotate(
managers_required=(Count('num_employees') / 4) + Count('num_managers'))
managers_required=(Count('num_employees') / 4) + Count('num_managers'))
...
@@ -314,6 +328,8 @@ Creating your own aggregate is extremely easy. At a minimum, you need
...
@@ -314,6 +328,8 @@ Creating your own aggregate is extremely easy. At a minimum, you need
to define ``function``, but you can also completely customize the
to define ``function``, but you can also completely customize the
SQL that is generated. Here's a brief example::
SQL that is generated. Here's a brief example::
from django.db.models import Aggregate
class Count(Aggregate):
class Count(Aggregate):
# supports COUNT(distinct field)
# supports COUNT(distinct field)
function = 'COUNT'
function = 'COUNT'
...
@@ -578,6 +594,7 @@ to play nice with other query expressions::
...
@@ -578,6 +594,7 @@ to play nice with other query expressions::
Let's see how it works::
Let's see how it works::
>>> from django.db.models import F, Value, CharField
>>> qs = Company.objects.annotate(
>>> qs = Company.objects.annotate(
... tagline=Coalesce([
... tagline=Coalesce([
... F('motto'),
... F('motto'),
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment