Django Cannot update a query once a slice has been taken
I have a query...
message_batch = Message.objects.all()[500]
I don't want to have to make another database call to retrieve the
objects, besides I already have them in memory so whats the point.
So I tried to update like this:
message_batch.update(send_date=datetime.datetime.now(), status="Sent")
But I get the following error message:
Cannot update a query once a slice has been taken.
Why? Is there a around around this? I want to update the objects I already
have in memory but make another call to retrieve them.
This is my full code, has to be way around this....
total = Message.objects.filter(status="Unsent", sender=user,
batch=batch).exclude(recipient_number__exact='').count()
for i in xrange(0,total,500):
message_batch =
Message.objects.filter(status="Unsent").exclude(recipient_number__exact='')[i:i+500]
# do some stuff here
#once all done update the objects
message_batch.update(send_date=datetime.datetime.now(),
billed=True)
No comments:
Post a Comment