#16211: using negated F()-expression in update query
---------------------------+-------------------------------
 Reporter:  wdoekes        |          Owner:  nobody
     Type:  Uncategorized  |         Status:  new
Milestone:                 |      Component:  Uncategorized
  Version:  1.2            |       Severity:  Normal
 Keywords:                 |   Triage Stage:  Unreviewed
Has patch:  0              |  Easy pickings:  0
    UI/UX:  0              |
---------------------------+-------------------------------
 Hi,

 as far as I can tell, there is currently no way to do this with the ORM:
 {{{
 UPDATE myapp_mymodel SET is_enabled = NOT is_enabled;
 }}}
 Using this:
 {{{
 MyModel.objects.update(is_enabled=(not F('is_enabled')))
 }}}
 .. becomes "is_enabled = true". And this:
 {{{
 MyModel.objects.update(is_enabled=~F('is_enabled'))
 }}}
 .. doesn't work, because the bitwise not operator is not defined on the
 `ExpressionNode`.

 I've done a patch against 1.2 to fix add that.

 It adds a unary "NOT"-connector to the `combine_expression` in
 `BaseDatabaseOperations` and it adds the `__invert__` method to the
 `ExpressionNode`.

 If you like this, I'll be happy to do a patch against trunk.

 Regards,[[br]]
 Walter Doekes[[br]]
 OSSO B.V.

-- 
Ticket URL: <https://code.djangoproject.com/ticket/16211>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to django-updates@googlegroups.com.
To unsubscribe from this group, send email to 
django-updates+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en.

Reply via email to