On Tue, Dec 1, 2009 at 5:09 PM, Continuation <selforgani...@gmail.com>wrote:
> In the doc, F() is used to update a single field atomically in one go. > Can I use it to update multiple fields and mixed it with non-F() field > updates? > > Using the example from doc (http://docs.djangoproject.com/en/dev/ref/ > models/instances/#updating-attributes-based-on-existing-fields<http://docs.djangoproject.com/en/dev/ref/%0Amodels/instances/#updating-attributes-based-on-existing-fields> > ) > > Can I do something like this - > > >>> from django.db.models import F > >>> product = Product.objects.get(name='Venezuelan Beaver Cheese') > >>> product.number_sold = F('number_sold') + 1 > >>> product.total_sales = F('total_sales') + 199.99 > >>> product.name = 'Cheddar Cheese > >>> product.save() > > When product.save() is executed in the above example, will both > number_sold & total_sales be updated atomically & name updated to > 'Cheddar Cheese'? > Assuming DEBUG is True in your settings file, >>> from django.db import connection >>> connection.queries[-1] issued right after your product.save() above will answer your question. Karen -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.