字符串操作函数
- django.db.models.functions.Concat
通过和Value
进行配合,给查询出来的对象添加一个新的字段,并且字段内容是通过Concat
函数组合成的字符串,如果是对象本身的属性,直接在Concat
中用字符串表示即可,如果是对象中没有的,则需要使用Value
函数表示
from django.db.models.functions import Concat
from django.db.models import Value
u = User.objects.filter(pk=1).annotate(concat_str=Concat(Value('username='), 'username', Value