Django queryset update fields with the lowercase equivalent – Django
Question:
I would like to update various models in go.
I need to update a varchar field with the lowercase equivalent.
Any idea if this can be done with a single queryset?
Answers:
Since this is a one-off it would be easier to just run ./manage.py dbshell
and run the UPDATE queries directly.
UPDATE sometable SET somefield=LOWER(somefield);
If you want to do it by using ORM, just try Database Functions.
You can make one fast call:
from django.db.models.functions import Lower
SomeModel.objects.update(somefield=Lower('somefield'))
I would like to update various models in go.
I need to update a varchar field with the lowercase equivalent.
Any idea if this can be done with a single queryset?
Since this is a one-off it would be easier to just run ./manage.py dbshell
and run the UPDATE queries directly.
UPDATE sometable SET somefield=LOWER(somefield);
If you want to do it by using ORM, just try Database Functions.
You can make one fast call:
from django.db.models.functions import Lower
SomeModel.objects.update(somefield=Lower('somefield'))