I have model action in RequestAdmin like this:def offer_plan(modeladmin, request, queryset):    class MembershipForm(forms.Form):        plan = forms.ModelChoiceField(queryset=Plan.objects.all(), required=True,empty_label=None)        _selected_action = forms.CharField(widget=forms.MultipleHiddenInput)        expires = forms.DateField(initial=click to select date)    selected = request.POST.getlist(admin.ACTION_CHECKBOX_NAME)    links = {}    if request.POST.get('submit'):        form = MembershipForm(request.POST)        if form.is_valid():            plan = form.cleaned_data['plan']            expires = form.cleaned_data['expires']            for _id in selected:                Request.objects.filter(id=_id).update(offered_membership_plan=plan,expires=expires)                links[Request.objects.filter(id=_id).get().email] = 'www.xyz.com/plan/' + str(int(_id))            return render_to_response(success.html, {'links': links,                }, context_instance=RequestContext(request))    else:        form = MembershipForm(initial={'_selected_action': selected})    return render_to_response(offer.html, {'form': form,        'selected_action': selected,}, context_instance=RequestContext(request))How can I improve the above code (I think it's always better not to run database calls in for loops) by removing database calls in loops?
Updating multiple membership plan expiration dates at once
python;database;django
You want to set the same values on multiple rows.  The query you want should be UPDATE Requests SET offered_membership_plan=, expires= WHERE id IN (, , ), and a way to achieve that would be:Request.objects.filter(id__in=selected).update(    offered_membership_plan=plan,    expires=expires)