#30053: Allow for conditional QuerySet.update_or_create()
-------------------------------------+-------------------------------------
     Reporter:  Joshua Cannon        |                    Owner:  Nasir
                                     |  Hussain
         Type:  New feature          |                   Status:  assigned
    Component:  Database layer       |                  Version:  master
  (models, ORM)                      |
     Severity:  Normal               |               Resolution:
     Keywords:  QuerySet             |             Triage Stage:
  update_or_create                   |  Unreviewed
    Has patch:  1                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------

Comment (by Simon Charette):

 Also, can't this be achieved by using `get_or_create` instead?

 {{{#!python
 with transaction.atomic():
     obj, created = objects.select_for_update().get_or_create(foo=bar,
 defaults=defaults)
     if not created and obj.date < minimal:
         # set obj attributes...
         obj.save(update_fields=...)
 }}}

 This would result in the same behaviour and only two queries.

-- 
Ticket URL: <https://code.djangoproject.com/ticket/30053#comment:13>
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 unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/068.369e17c45893d4eea003cef4e3c5d3ca%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to