>
> Not that I am completely convinced that the following is a good idea; but
> what about:

QuerySet.objects.update(name="Rob").values("id", "name")
>

That's not possible since update() directly performs the update - it's not
lazy in any way. It could be done in the other order like
`QuerySet.objects.values("id", "name").update(name="Rob")` but I don't see
the necessity to define "returning" fields in a chainable manner.

On Tue, 26 Jan 2021 at 14:59, Florian Apolloner <f.apollo...@gmail.com>
wrote:

> Not that I am completely convinced that the following is a good idea; but
> what about:
>
> QuerySet.objects.update(name="Rob").values("id", "name")
>
> On second thought I'd like an .returning() more than values, but I am not
> sure if it makes sense to add a new function just for the sake of a small
> backwards compatibility.
>
> > I'd expect it to return a list of dicts.
>
> Currently .update returns the number of rows affected I think. This
> information should still be there even if returning extra data.
> On Tuesday, January 26, 2021 at 3:00:01 PM UTC+1 Adam Johnson wrote:
>
>> I think we could do the most logical:
>>
>> QuerySet.objects.update(name="Rob", returning=["id', "name"])
>>
>> There is a precedent for small backwards incompatible changes like this,
>> for example when "named" was added to "values_list()". However maybe
>> backwards compatibility is worth keeping. We can be backwards compatible by
>> special-casing models with a field called 'returning', in which case the
>> field is updated. This blocks the 'returning' functionality but users can
>> always rename a field.
>>
>> I'd rather not add a new method or otherwise change the signature of
>> update() more radically.
>>
>> On Tue, 26 Jan 2021 at 13:27, Tom Carrick <t...@carrick.eu> wrote:
>>
>>> Hi,
>>>
>>> I found myself with a use-case today of wanting to return some data from
>>> an update, as I want to make sure I return exactly what is in the database
>>> without making an extra query.
>>>
>>> I've found https://code.djangoproject.com/ticket/28682 and agree with
>>> the resolution there.
>>>
>>> I suppose there is a way to do this in a backwards compatible way,
>>> something like:
>>>
>>> Foo.objects.update(["id", "name"], name="Rob")
>>>
>>> But it's very ugly. But how about a new method:
>>>
>>> Foo.objects.update_returning(["id", "name"], name="Rob")
>>>
>>> Doesn't seem quite so bad. There's also a possibility of something like:
>>>
>>> Foo.objects.update_returning(updates={"name": "Rob"}, returning=["id",
>>> "name"])
>>>
>>> I'd expect it to return a list of dicts. I'm not sure what's best, if
>>> anything. It could be it's a bit too niche, but it is sometimes quite
>>> useful.
>>>
>>> Tom
>>>
>>> --
>>> You received this message because you are subscribed to the Google
>>> Groups "Django developers (Contributions to Django itself)" group.
>>> To unsubscribe from this group and stop receiving emails from it, send
>>> an email to django-develop...@googlegroups.com.
>>> To view this discussion on the web visit
>>> https://groups.google.com/d/msgid/django-developers/CAHoz%3DMaDz7VLXqRk01D_bUOLN%3D5TBiqVrw-BzyLogeaTMtXM4g%40mail.gmail.com
>>> <https://groups.google.com/d/msgid/django-developers/CAHoz%3DMaDz7VLXqRk01D_bUOLN%3D5TBiqVrw-BzyLogeaTMtXM4g%40mail.gmail.com?utm_medium=email&utm_source=footer>
>>> .
>>>
>>
>>
>> --
>> Adam
>>
> --
> You received this message because you are subscribed to the Google Groups
> "Django developers (Contributions to Django itself)" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-developers+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-developers/abde0155-3eb9-4330-994a-c5f9133b236an%40googlegroups.com
> <https://groups.google.com/d/msgid/django-developers/abde0155-3eb9-4330-994a-c5f9133b236an%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>


-- 
Adam

-- 
You received this message because you are subscribed to the Google Groups 
"Django developers  (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-developers+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-developers/CAMyDDM0ZwMTcxGKoQ4Ch%2Bv85b0hd0CseocioWCFkxTXbgJDCPQ%40mail.gmail.com.

Reply via email to