Skip to content

Instantly share code, notes, and snippets.

@walkness
Last active September 2, 2024 13:15
Show Gist options
  • Select an option

  • Save walkness/a7e6529376a53297231c287db55d2f02 to your computer and use it in GitHub Desktop.

Select an option

Save walkness/a7e6529376a53297231c287db55d2f02 to your computer and use it in GitHub Desktop.
Django regex replace for PostgreSQL
from django.db.models import Func, F, Value
from images.models import Image
Image.objects.all().update(original_filename=Func(F('file'), Value('^.*\/(.*)$'), Value('\\1'), function='regexp_replace'))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment