On a few occasions I've found myself doing something like:
instance, created =
Model.objects.get_or_create(something=something, ..., defaults={
'somethingelse': somethingelse,
...
})
if not created:
instance. somethingelse = somethingelse
...
instance.save()
I'd like to propo
Most of the times i have some extra condition in there.
if not created and modified>instance.modified:
for key, value in defaults_dict.items():
setattr(instance, key, value)
instance.save()
Now this extra clause can be fairly arbitrary.
A generic piece of code could check if there's an
On Sep 10, 11:04 pm, Tai Lee <[EMAIL PROTECTED]> wrote:
> I'd like to propose a `create_or_update` method, similar to
> `get_or_create`
FYI: there is an old ticket (with patch) for this called
update_or_create [1].
.. [1] http://code.djangoproject.com/ticket/3182
--~--~-~--~~