当前位置: 首页>>代码示例>>Python>>正文


Python functions.Upper方法代码示例

本文整理汇总了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],
        ) 
开发者ID:denisenkom,项目名称:django-sqlserver,代码行数:23,代码来源:tests.py

示例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],
        ) 
开发者ID:denisenkom,项目名称:django-sqlserver,代码行数:23,代码来源:tests.py

示例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],
        ) 
开发者ID:nesdis,项目名称:djongo,代码行数:22,代码来源:tests.py

示例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],
        ) 
开发者ID:nesdis,项目名称:djongo,代码行数:22,代码来源:tests.py

示例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)
        ) 
开发者ID:nesdis,项目名称:djongo,代码行数:21,代码来源:test_upper.py

示例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"] 
开发者ID:adamchainz,项目名称:django-mysql,代码行数:13,代码来源:test_functions.py

示例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"] 
开发者ID:adamchainz,项目名称:django-mysql,代码行数:16,代码来源:test_functions.py

示例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')) 
开发者ID:PUNCH-Cyber,项目名称:YaraGuardian,代码行数:17,代码来源:managers.py

示例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"))) 
开发者ID:adamchainz,项目名称:django-perf-rec,代码行数:5,代码来源:test_api.py

示例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) 
开发者ID:nesdis,项目名称:djongo,代码行数:7,代码来源:test_checks.py

示例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'}) 
开发者ID:nesdis,项目名称:djongo,代码行数:16,代码来源:tests.py

示例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'}) 
开发者ID:nesdis,项目名称:djongo,代码行数:12,代码来源:tests.py

示例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
        ) 
开发者ID:nesdis,项目名称:djongo,代码行数:13,代码来源:tests.py

示例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
            ) 
开发者ID:nesdis,项目名称:djongo,代码行数:13,代码来源:test_upper.py

示例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
        ) 
开发者ID:nesdis,项目名称:djongo,代码行数:11,代码来源:test_substr.py


注:本文中的django.db.models.functions.Upper方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。