Q:

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 not 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)

A:

You can update objects by their primary keys:
base_qs = Message.objects.filter(status="Unsent", sender=user, batch=batch).exclude(recipient_number__exact='')
total = base_qs.count()

for i in xrange(0, total, 500):
    page = list(base_qs[i:i+500])
    page_ids = [o.pk for o in page]
    # Do some stuff here
    base_qs.filter(pk__in=page_ids).update(send_date=datetime.datetime.now(), billed=True)

