I wish to update a Django model field of objects in a queryset. To be specific, I want to add a prefix on one of the fields i.e. if an object has a name like 'Wilson', I want to prefix it with 'OLD', then it will become 'OLDWilson'.
I can think of the following using loops:
my_objs = MyObjects.objects.filter(name='some_name') # This has over 40000 records
for obj in my_objs:
obj.name = 'OLD{0}'.format(obj.name)
obj.save()
I was hoping of a more elegant way to take advantage of the UPDATE
method as specified here: Django Mass Update
Something like the following:
MyObjects.objects.filter(name='some_name').update(name='OLD+name_here')
Any pointers on how I can achieve this?