Opened 10 years ago
Last modified 11 months ago
#25195 new New feature
update_or_create doesn't understand F() operations
Description ¶
This may not be possible to resolve, but it would be really nice if you could do something like
Foo.objects.update_or_create(name='bar', defaults={'value': F('value') + 1})
This would only be possible when value has a default, and we would need to resolve the F() object to the default. It may be that we need a different object which resolves to an expression when used in an update but resolves differently when used in a create.
According to the ticket's flags, the next step(s) to move this issue forward are:
- To provide a patch by sending a pull request. Claim the ticket when you start working so that someone else doesn't duplicate effort. Before sending a pull request, review your work against the patch review checklist. Check the "Has patch" flag on the ticket after sending a pull request and include a link to the pull request in the ticket comment when making that update. The usual format is:
[https://github.com/django/django/pull/#### PR]
.
Change History (4)
comment:1 by , 10 years ago
Triage Stage: | Unreviewed → Accepted |
---|
follow-up: 3 comment:2 by , 6 years ago
comment:3 by , 6 years ago
Replying to Marc Parizeau:
How about the following?
Foo.objects.update_or_create(name='bar', defaults={'value': Coalesce('value', 0) + 1})where one could specify an explicit default?
We'd need to special case Coalesce
in update_or_create
for this to work as references to columns are not allowed in INSERT
s. In other words, Coalesce('value', 0) + 1
exhibits the same limitations that F('value') + 1
has in create
.
comment:4 by , 11 months ago
Cc: | added |
---|
How about the following?
where one could specify an explicit default?