Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save avdata99/f5d8e9844e2308acc48e35318cadd73f to your computer and use it in GitHub Desktop.
Save avdata99/f5d8e9844e2308acc48e35318cadd73f to your computer and use it in GitHub Desktop.
from django.db.models import F, Func, Value
# todos
MyModel.objects.all()
.update(
campo_a_reemplazar=Func(
F('campo_a_reemplazar_u_otro'),
Value('txt_buscar'),
Value('txt_reemplazar'),
function='replace'))
# algunos filtrando
MyModel.objects.filter(campo='algo')
.update(
campo_a_reemplazar=Func(
F('campo_a_reemplazar_u_otro'),
Value('txt_buscar'),
Value('txt_reemplazar'),
function='replace'))
# algunos excluyendo
MyModel.objects.exclude(alicuota='')
.update(
campo_a_reemplazar=Func(
F('campo_a_reemplazar_u_otro'),
Value('txt_buscar'),
Value('txt_reemplazar'),
function='replace'))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment