久久久久久AV无码免费看大片,亚洲一区精品人人爽人人躁,国产成人片无码免费爱线观看,亚洲AV成人无码精品网站,为什么晚上搞的时候要盖被子

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

時間:2022-01-12 10:33:57 類型:python
字號:    
#方法一:
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)用原生方法


<