当前位置: 首页>>编程示例 >>用法及示例精选 >>正文


Python Django Substr用法及代码示例

本文介绍 django.db.models.functions.Substr 的用法。

声明

class Substr(expression, pos, length=None, **extra)

从位置 pos 开始的字段或表达式返回长度为 length 的子字符串。该位置是 1 索引的,因此该位置必须大于 0。如果 lengthNone ,则将返回字符串的其余部分。

使用示例:

>>> # Set the alias to the first 5 characters of the name as lowercase
>>> from django.db.models.functions import Lower, Substr
>>> Author.objects.create(name='Margaret Smith')
>>> Author.objects.update(alias=Lower(Substr('name', 1, 5)))
1
>>> print(Author.objects.get(name='Margaret Smith').alias)
marga

相关用法


注:本文由纯净天空筛选整理自djangoproject.com大神的英文原创作品 django.db.models.functions.Substr。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。