#30053: Allow for conditional QuerySet.update_or_create()
-------------------------------------+-------------------------------------
Reporter: Joshua | Owner: nobody
Cannon |
Type: New | Status: new
feature |
Component: Database | Version: master
layer (models, ORM) | Keywords: QuerySet
Severity: Normal | update_or_create
Triage Stage: | Has patch: 0
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------+-------------------------------------
{{{QuerySet.update_or_create()}}} is great since it lifts the burden of
thread-safety and repeated code from the client. However there exists some
scenarios where the "update" logic should be hidden behind a condition.
(E.g. only update if the value of a {{{DateTimeField}}} is less than
somevalue). There isn't much help for clients in these scenarios, with the
best solution being to copy+paste {{{QuerySet.update_or_create()}}} and
add a condition to the {{{if created:}}} expression.
The condition would most likely be a callable that accepts one argument,
the {{{got}}}ten instance.
The solution should be trivial, either:
A. Add a "condition" parameter to {{{update_or_create()}}} (along with
logic to make the feature backwards compatible, likely checking if the
value is callable with one argument or not, since "condition" could be a
field)
B. Add another method, and re-write {{{update_or_create()}}} in terms of
the new method with a condition that is always true.
--
Ticket URL: <https://code.djangoproject.com/ticket/30053>
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/053.21c4f20dcd3a0f56935f5bda167a950e%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.