I have a view that add and edit Meeting objects and I’m going to after saving a Meeting object show a list of participants of that object,how can I return a list of participants with HttpResponseRedirect ? I don’t think it be possible to send a big list of objects via query string !
in views.py
def addMeeting(request,meeting_id=None):
message=u''
participants=Participant.objects.filter(meeting__id=meeting_id)
if request.GET.get('save'):
message='your recorded was registered'
if meeting_id:
meeting_instance=Meeting.objects.get(pk=meeting_id)
else:
meeting_instance=Meeting()
if request.method=='POST':
meetingform=MeetingForm(request.POST,instance=meeting_instance)
if meetingform.is_valid():
meeting=meetingform.save()
meeting.save()
redirect_url=reverse('MeetingManagerHub.views.addMeeting', args=[meeting.pk])
return HttpResponseRedirect(redirect_url+'?save=True')
else:
meetingform=MeetingForm(instance=meeting_instance)
return render_to_response('MeetingHub/addmeeting.html', {'meetingform': meetingform,'message':message},context_instance=RequestContext(request))
in urls.py
(r'^meeting/add/$','MeetingManagerHub.views.addMeeting'),
(r'^meeting/add/(?P<meeting_id>\d+)/$','MeetingManagerHub.views.addMeeting'),
I googled alot and finally found out that HttpResponseRedirect just redirect us to a new address and doesn’t work with context!
how can I do this?
There’s a secret to this. A Redirect should points to a view which gets the meeting AND the participants.
Often, that’s a simple view function that handles simple GET requests and returns the meeting and the list of participants.
If you’re going to redirect back to this
addMeetingview function, then the GET processing needs to query meetings AND the participants.That means that the
render_to_responsemust include the meeting AND the participants.