日韩精品欧美激情国产一区_中文无码精品一区二区三区在线_岛国毛片AV在线无码不卡_亞洲歐美日韓精品在線_使劲操好爽好粗视频在线播放_日韩一区欧美二区_八戒八戒网影院在线观看神马_亚洲怡红院在线色网_av无码不卡亚洲电影_国产麻豆媒体MDX

使用字符串替換的Django批量更新replace方法的使用

時(shí)間:2022-01-12 10:33:57 類(lèi)型:python
字號(hào):    
#方法一:
for entry in ExampleModel.objects.all():
    entry.string_field = entry.string_field.replace('old text', 'new text', 1)
    entry.save()

#方法二:
from django.db.models import F, Func, Value

ExampleModel.objects.filter(<condition>).update(
    string_field=Func(        F('string_field'),        Value('old text'), Value('new text'),
        function='replace',
    )
)

#方法三:

from django.db.models import Value
from django.db.models.functions import Replace

ExampleModel.objects.filter(<condition>).update(
    string_field=Replace('name', Value('old text'), Value('new text'))
)

#方法四:
#Django直接調(diào)用原生方法


<