【发布时间】:2021-03-09 15:16:05
【问题描述】:
【问题讨论】:
-
您可以使用
Funcexpression创建自定义数据库函数
标签: django postgresql hash orm
【问题讨论】:
Func expression创建自定义数据库函数
标签: django postgresql hash orm
对于 Django 的 User 模型,它将如下所示:
from django.contrib.auth.models import User
from django.db.models import Concat, Func, CharField
User.objects.annotate(
hash=Func(
Concat('first_name', 'last_name', output_field=CharField()),
function='md5',
)
)
【讨论】:
result[0].hash。