Posts

Showing posts from March, 2020

django tagging

django update string value with using existing value

it's possible to use F queries to make updates with using existing values in database, it's quite easy if value is number but when you want to do updates on string values things are getting complicated  a bit Here below I am replacing empty char coming after comma in location field such as London, UK We need to use django's special functions for this purpose F Value and Func from django.db.models import F, Func, Value Developer.objects.filter(location__contains=", ").update(location=Func(         F('location'),         Value(', '), Value(','),         function='replace',     )) Result will be London,UK which is our intended solution