I have a straightforward form that simply reduces an item count by 1, for a selected product. (The form essentially "ships" a product, so need to decrease remaining term_length by 1).
I have the following code:
cd = form.cleaned_data
q = Subscription.objects.filter(product_key__exact = cd['product'])
q = q.filter(status__iexact='Active')
q = q.filter(term_length__gt=0)
# Decrement our terms remaining by 1.
rec_count = q.update(term_length=F('term_length') - 1)
return render_to_response('subs/shipped.html',{ 'q': q, 'rec_count': rec_count })
What happens is that the results I want to display on the "shipped" page are still being filtered according to the criteria I used to select the rows for updating. Since I have a >= 0 filter, I do not see those rows that were reduced from 1 to 0. I can't use {{ q|length }} to get number of records updated, for example.
How would I go about returning, for example, a list of the freshly updated records from BEFORE they were updated. I can't search after the fact, since status and term_length would be Inactive and 0 for a huge number of records; there will be nothing distinct about the ones that were last changed.
Thanks for the help.
M.