How to ‘bulk update’ with Django?

I’d like to update a table with Django – something like this in raw SQL:

update tbl_name set name="foo" where name="bar"

My first result is something like this – but that’s nasty, isn’t it?

list = ModelClass.objects.filter(name="bar")
for obj in list:
    obj.name="foo"
    obj.save()

Is there a more elegant way?

7 Answers
7

Leave a Comment