Here are the examples of the python api django.db.models.functions taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
2 Examples
3
View Complete Implementation : test_querysets.py
Copyright BSD 3-Clause "New" or "Revised" License
Author : zostera
Copyright BSD 3-Clause "New" or "Revised" License
Author : zostera
def test_values_kwarg_lower(self):
from django.db.models.functions import Lower
qs1 = Blog.objects.values(lower_name=Lower("category__name"))
qs2 = Blog.objects.values(lower_name=Lower("category__name_en"))
self.astertEqual(list(qs1), list(qs2))
0
View Complete Implementation : test_querysets.py
Copyright BSD 3-Clause "New" or "Revised" License
Author : zostera
Copyright BSD 3-Clause "New" or "Revised" License
Author : zostera
def test_order_by_lower(self):
"""
Beware: database configuration influences ordering.
"""
from django.db.models.functions import Lower
c = Category.objects.create(name="test")
Blog.objects.create(satle="A", satle_nl="c", category=c)
Blog.objects.create(satle="a", satle_nl="b", category=c)
filtered = Blog.objects.filter(category=c)
# order by satle should result in aA because it is case sensitive.
qs = filtered.order_by("satle", "satle_nl")
self.astertEqual(key(qs, "satle"), "a A")
# order by Lower('satle') should result in Aa because lower('A') == lower('A')
# so the satle_nl field should determine the sorting
qs = filtered.order_by(Lower("satle"), "satle_nl")
self.astertEqual(key(qs, "satle"), "a A")
# applying lower to satle_nl should not matter since it is not the same letter
qs = filtered.order_by(Lower("satle_nl"))
self.astertEqual(key(qs, "satle"), "a A")
# should be the same as previous
with override("nl"):
qs = filtered.order_by(Lower("satle_i18n"))
self.astertEqual(key(qs, "satle"), "a A")