This code runs on cron. So I want to update the status of the objects immediately so that these objects don't get picked up again if a second cron starts before the current one finishes (which will eventually start to happen with my app.)
# Grab all pending emails.
emails = delivery_que.objects.filter(status='PENDING')
emails.update(status='SENDING')
# Loop through the pending emails.
for email in emails:
The current code doesn't work, as I seem to no longer have access to the objects after I .update() them.
This is the workaround I implemented:
# Grab all pending emails.
emails = delivery_que.objects.filter(status='PENDING')
emails.update(status='SENDING')
emails = delivery_que.objects.filter(status='SENDING')
# Loop through the pending emails.
for email in emails:
Is there another better solution I'm missing? I'd prefer not to query the database again to reselect the objects that I should already have access to from the first query.