#32406: Allow QuerySet.update() to return fields on supported backends.
-------------------------------------+-------------------------------------
Reporter: Tom Carrick | Owner: Aivars
| KalvÄns
Type: New feature | Status: assigned
Component: Database layer | Version: dev
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by James Beith):
Hi all
I asked a [https://forum.djangoproject.com/t/refresh-generatedfield-
column-when-calling-save/36437 question on the Django forums] about
whether it would be possible to use the RETURNING SQL clause when calling
`save()` on a Django model instance. In that thread I got pointed here
which has some overlap (also to ticket #27222).
If there was a desire to support UPDATE RETURNING for the `Model.save()`
method, were there any thoughts in relation to having a similar/consistent
API to what's being proposed here for the `QuerySet.update()` method?
I believe from this ticket currently the preferred suggestion for
`QuerySet.update()` is adding a new `returning` kwarg, e.g.
{{{#!python
QuerySet.update(x=1, y=2, returning=True)
}}}
Could this work for `Model.save()` method too? Which would return all
fields, e.g.
{{{#!python
Model.save(returning=True)
}}}
And if we combined it with `update_fields` would that return only those
fields (or all)? e.g.
{{{#!python
Model.save(update_fields=["x", "y"], returning=True)
}}}
If the forum post it was also suggested by Simon whether a separate
`returning_fields` could be used, which of course would mean the `Model`
and `QuerySet` APIs were different (but maybe for good reason). e.g.
{{{#!python
Model.save(returning_fields=["x", "y"])
Model.save(update_fields=["x", "y"], returning_fields=["x", "y"])
}}}
Thanks in advanced,
James
--
Ticket URL: <https://code.djangoproject.com/ticket/32406#comment:21>
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 view this discussion visit
https://groups.google.com/d/msgid/django-updates/01070195abc42f46-9699c2a9-b16a-41b2-a701-98e20917ebe2-000000%40eu-central-1.amazonses.com.