Changes between Version 1 and Version 3 of Ticket #30053


Ignore:
Timestamp:
Dec 21, 2018, 9:53:15 AM (5 years ago)
Author:
Joshua Cannon
Comment:

Legend:

Unmodified
Added
Removed
Modified
  • Ticket #30053 – Description

    v1 v3  
    1 {{{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 some value). 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.
     1{{{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 some value). There isn't much help for clients in these scenarios, with the best solution being to copy+paste {{{QuerySet.update_or_create()}}} and wrap the {{{setattr}}}-and-{{{save}}} logic in a conditional (worst case being they roll their own code, which likely would lead to thread-safety issues)
    22
    33The condition would most likely be a callable that accepts one argument, the {{{got}}}ten instance.
Back to Top