tags:

views:

67

answers:

2

How do I run an update and select statement on the same queryset rather than having to do 2 queries, one to select the object and one to update the object?

The equivalent in SQL would be something like:

update my_table set field_1 = 'some value' where pk_field = some_value
+5  A: 

Use the queryset update method:

MyModel.objects.filter(pk=some_value).update(field1='some value')
Daniel Roseman
+1  A: 

Here is the documentation from the Django website: http://docs.djangoproject.com/en/1.1/topics/db/queries/#updating-multiple-objects-at-once

JayhawksFan93