Hi, I think QuerySet.update works to inflexible. In SQL you can define expressions containing the current value or the value of an other column in the update clause, for Example to incrementing a value in the result set. This is not possible by the ORM at the moment.
I developed a possible solution, by introducing combinable Expression objects. Look at http://code.djangoproject.com/ticket/7210. This patch allows you to do following: from django.db.models.sql.expressions import * qset = model.objects.all() # Equivalent to qset.update(foo=42) qset.update(foo=LiteralExpr(42)) # Increment column 'foo' by one. qset.update(foo=CurrentExpr() + LiteralExpr(1)) # Swap the value of the column 'foo' and 'bar'. qset.update(foo=ColumnExpr('bar'), bar=ColumnExpr('foo')) Does somebody thinks there are reasons to don't merge this patch? Or ideas ti even improve this patch? Thanks. Regards Sebastian Noack
signature.asc
Description: PGP signature