本文整理匯總了Python中django.db.models.functions.Upper方法的典型用法代碼示例。如果您正苦於以下問題:Python functions.Upper方法的具體用法?Python functions.Upper怎麽用?Python functions.Upper使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類django.db.models.functions
的用法示例。
在下文中一共展示了functions.Upper方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_order_by_nulls_last
# 需要導入模塊: from django.db.models import functions [as 別名]
# 或者: from django.db.models.functions import Upper [as 別名]
def test_order_by_nulls_last(self):
self.skipTest("TODO fix django.db.utils.ProgrammingError: Incorrect syntax near 'NULLS'.")
Article.objects.filter(headline="Article 3").update(author=self.author_1)
Article.objects.filter(headline="Article 4").update(author=self.author_2)
# asc and desc are chainable with nulls_last.
self.assertSequenceEqual(
Article.objects.order_by(F("author").desc(nulls_last=True)),
[self.a4, self.a3, self.a1, self.a2],
)
self.assertSequenceEqual(
Article.objects.order_by(F("author").asc(nulls_last=True)),
[self.a3, self.a4, self.a1, self.a2],
)
self.assertSequenceEqual(
Article.objects.order_by(Upper("author__name").desc(nulls_last=True)),
[self.a4, self.a3, self.a1, self.a2],
)
self.assertSequenceEqual(
Article.objects.order_by(Upper("author__name").asc(nulls_last=True)),
[self.a3, self.a4, self.a1, self.a2],
)
示例2: test_order_by_nulls_first
# 需要導入模塊: from django.db.models import functions [as 別名]
# 或者: from django.db.models.functions import Upper [as 別名]
def test_order_by_nulls_first(self):
self.skipTest("TODO fix django.db.utils.ProgrammingError: Incorrect syntax near 'NULLS'.")
Article.objects.filter(headline="Article 3").update(author=self.author_1)
Article.objects.filter(headline="Article 4").update(author=self.author_2)
# asc and desc are chainable with nulls_first.
self.assertSequenceEqual(
Article.objects.order_by(F("author").asc(nulls_first=True)),
[self.a1, self.a2, self.a3, self.a4],
)
self.assertSequenceEqual(
Article.objects.order_by(F("author").desc(nulls_first=True)),
[self.a1, self.a2, self.a4, self.a3],
)
self.assertSequenceEqual(
Article.objects.order_by(Upper("author__name").asc(nulls_first=True)),
[self.a1, self.a2, self.a3, self.a4],
)
self.assertSequenceEqual(
Article.objects.order_by(Upper("author__name").desc(nulls_first=True)),
[self.a1, self.a2, self.a4, self.a3],
)
示例3: test_order_by_nulls_last
# 需要導入模塊: from django.db.models import functions [as 別名]
# 或者: from django.db.models.functions import Upper [as 別名]
def test_order_by_nulls_last(self):
Article.objects.filter(headline="Article 3").update(author=self.author_1)
Article.objects.filter(headline="Article 4").update(author=self.author_2)
# asc and desc are chainable with nulls_last.
self.assertQuerysetEqualReversible(
Article.objects.order_by(F("author").desc(nulls_last=True), 'headline'),
[self.a4, self.a3, self.a1, self.a2],
)
self.assertQuerysetEqualReversible(
Article.objects.order_by(F("author").asc(nulls_last=True), 'headline'),
[self.a3, self.a4, self.a1, self.a2],
)
self.assertQuerysetEqualReversible(
Article.objects.order_by(Upper("author__name").desc(nulls_last=True), 'headline'),
[self.a4, self.a3, self.a1, self.a2],
)
self.assertQuerysetEqualReversible(
Article.objects.order_by(Upper("author__name").asc(nulls_last=True), 'headline'),
[self.a3, self.a4, self.a1, self.a2],
)
示例4: test_order_by_nulls_first
# 需要導入模塊: from django.db.models import functions [as 別名]
# 或者: from django.db.models.functions import Upper [as 別名]
def test_order_by_nulls_first(self):
Article.objects.filter(headline="Article 3").update(author=self.author_1)
Article.objects.filter(headline="Article 4").update(author=self.author_2)
# asc and desc are chainable with nulls_first.
self.assertQuerysetEqualReversible(
Article.objects.order_by(F("author").asc(nulls_first=True), 'headline'),
[self.a1, self.a2, self.a3, self.a4],
)
self.assertQuerysetEqualReversible(
Article.objects.order_by(F("author").desc(nulls_first=True), 'headline'),
[self.a1, self.a2, self.a4, self.a3],
)
self.assertQuerysetEqualReversible(
Article.objects.order_by(Upper("author__name").asc(nulls_first=True), 'headline'),
[self.a1, self.a2, self.a3, self.a4],
)
self.assertQuerysetEqualReversible(
Article.objects.order_by(Upper("author__name").desc(nulls_first=True), 'headline'),
[self.a1, self.a2, self.a4, self.a3],
)
示例5: test_basic
# 需要導入模塊: from django.db.models import functions [as 別名]
# 或者: from django.db.models.functions import Upper [as 別名]
def test_basic(self):
Author.objects.create(name='John Smith', alias='smithj')
Author.objects.create(name='Rhonda')
authors = Author.objects.annotate(upper_name=Upper('name'))
self.assertQuerysetEqual(
authors.order_by('name'), [
'JOHN SMITH',
'RHONDA',
],
lambda a: a.upper_name
)
Author.objects.update(name=Upper('name'))
self.assertQuerysetEqual(
authors.order_by('name'), [
('JOHN SMITH', 'JOHN SMITH'),
('RHONDA', 'RHONDA'),
],
lambda a: (a.upper_name, a.name)
)
示例6: test_if_with_string_values
# 需要導入模塊: from django.db.models import functions [as 別名]
# 或者: from django.db.models.functions import Upper [as 別名]
def test_if_with_string_values(self):
Alphabet.objects.create(a=1, d="Lentils")
Alphabet.objects.create(a=2, d="Cabbage")
Alphabet.objects.create(a=3, d="Rice")
result = list(
Alphabet.objects.annotate(conditional=If(Q(a=2), Upper("d"), Lower("d")))
.order_by("id")
.values_list("conditional", flat=True)
)
assert result == ["lentils", "CABBAGE", "rice"]
示例7: test_if_field_lookups_work
# 需要導入模塊: from django.db.models import functions [as 別名]
# 或者: from django.db.models.functions import Upper [as 別名]
def test_if_field_lookups_work(self):
Alphabet.objects.create(a=1, d="Lentils")
Alphabet.objects.create(a=2, d="Cabbage")
Alphabet.objects.create(a=3, d="Rice")
result = list(
Alphabet.objects.annotate(
conditional=If(Q(a__gte=2), Upper("d"), Value(""))
)
.filter(conditional__startswith="C")
.order_by("id")
.values_list("conditional", flat=True)
)
assert result == ["CABBAGE"]
示例8: change_name_case
# 需要導入模塊: from django.db.models import functions [as 別名]
# 或者: from django.db.models.functions import Upper [as 別名]
def change_name_case(self, operation, modifier=None):
available_operations = {'lowercase': lowercase,
'uppercase': uppercase}
edit = available_operations.get(operation, None)
if edit and modifier:
modification = edit(modifier)
self.update(name=REPLACE('name', Value(modifier), Value(modification)))
elif operation == 'lowercase':
self.update(name=Lower('name'))
elif operation == 'uppercase':
self.update(name=Upper('name'))
示例9: test_non_deterministic_QuerySet_annotate
# 需要導入模塊: from django.db.models import functions [as 別名]
# 或者: from django.db.models.functions import Upper [as 別名]
def test_non_deterministic_QuerySet_annotate(self):
with record():
list(Author.objects.annotate(x=Upper("name"), y=Upper("name")))
示例10: test_valid_expression
# 需要導入模塊: from django.db.models import functions [as 別名]
# 或者: from django.db.models.functions import Upper [as 別名]
def test_valid_expression(self):
class TestModelAdmin(ModelAdmin):
ordering = (Upper('name'), Upper('band__name').desc())
self.assertIsValid(TestModelAdmin, ValidationTestModel)
示例11: test_specified_ordering_by_f_expression
# 需要導入模塊: from django.db.models import functions [as 別名]
# 或者: from django.db.models.functions import Upper [as 別名]
def test_specified_ordering_by_f_expression(self):
class OrderedByFBandAdmin(admin.ModelAdmin):
list_display = ['name', 'genres', 'nr_of_members']
ordering = (
F('nr_of_members').desc(nulls_last=True),
Upper(F('name')).asc(),
F('genres').asc(),
)
m = OrderedByFBandAdmin(Band, custom_site)
request = self.factory.get('/band/')
request.user = self.superuser
cl = m.get_changelist_instance(request)
self.assertEqual(cl.get_ordering_field_columns(), {3: 'desc', 2: 'asc'})
示例12: test_specified_ordering_by_f_expression_without_asc_desc
# 需要導入模塊: from django.db.models import functions [as 別名]
# 或者: from django.db.models.functions import Upper [as 別名]
def test_specified_ordering_by_f_expression_without_asc_desc(self):
class OrderedByFBandAdmin(admin.ModelAdmin):
list_display = ['name', 'genres', 'nr_of_members']
ordering = (F('nr_of_members'), Upper('name'), F('genres'))
m = OrderedByFBandAdmin(Band, custom_site)
request = self.factory.get('/band/')
request.user = self.superuser
cl = m.get_changelist_instance(request)
self.assertEqual(cl.get_ordering_field_columns(), {3: 'asc', 2: 'asc'})
示例13: test_function_as_filter
# 需要導入模塊: from django.db.models import functions [as 別名]
# 或者: from django.db.models.functions import Upper [as 別名]
def test_function_as_filter(self):
Author.objects.create(name='John Smith', alias='SMITHJ')
Author.objects.create(name='Rhonda')
self.assertQuerysetEqual(
Author.objects.filter(alias=Upper(V('smithj'))),
['John Smith'], lambda x: x.name
)
self.assertQuerysetEqual(
Author.objects.exclude(alias=Upper(V('smithj'))),
['Rhonda'], lambda x: x.name
)
示例14: test_transform
# 需要導入模塊: from django.db.models import functions [as 別名]
# 或者: from django.db.models.functions import Upper [as 別名]
def test_transform(self):
with register_lookup(CharField, Upper):
Author.objects.create(name='John Smith', alias='smithj')
Author.objects.create(name='Rhonda')
authors = Author.objects.filter(name__upper__exact='JOHN SMITH')
self.assertQuerysetEqual(
authors.order_by('name'), [
'John Smith',
],
lambda a: a.name
)
示例15: test_expressions
# 需要導入模塊: from django.db.models import functions [as 別名]
# 或者: from django.db.models.functions import Upper [as 別名]
def test_expressions(self):
Author.objects.create(name='John Smith', alias='smithj')
Author.objects.create(name='Rhonda')
substr = Substr(Upper('name'), StrIndex('name', V('h')), 5, output_field=CharField())
authors = Author.objects.annotate(name_part=substr)
self.assertQuerysetEqual(
authors.order_by('name'), ['HN SM', 'HONDA'],
lambda a: a.name_part
)