S
S
Sergey Eremin2021-03-16 18:37:56
Django
Sergey Eremin, 2021-03-16 18:37:56

How to do something like Tb.objects.all()[:N].update(que=quie_id]) in Django?

In short, let's say there is a Django service that regularly, but relatively rarely, receives a bunch of data and distributes tasks among several other services that will process the data, put it in drives (and drives are finite), etc. Processing services work unevenly, some services have accumulated tasks from previous periods that have not yet been fired, and all this must be taken into account when distributing. When, the distribution service determines what, say, Nobjects from the table should Tbbe distributed for processing to the service que=quie_id, and here it is logical to apply the following construction:

Tb.objects.all()[:N].update(que=quie_id])

But Django cannot do updateby [:N]. At the same time, Nit is quite large and it takes a long time to go through the entire queryset and change records one at a time. How to proceed to do a group update on a limited queryset?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dr. Bacon, 2021-03-16
@Sergei_Erjemin

Tb.objects.filter(pk__in=Tb.objects.all()[:N]).update(que=quie_id)

And if so? Well, add values ​​('pk') if it will swear

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question