1

I'm trying to pass a list between two views and am currently using session variables to do so.

def EnrollmentVerification(request):
    session_enrollments = Enrollment.objects.filter(id__in=request.session["enrollments"])
    if request.method == 'POST':
        form = EnrollmentVerificationForm(request.POST)
        if form.is_valid():
            # doing stuff
    else:
        form = EnrollmentVerificationForm(initial={'enrollments': session_enrollments})
    return render_to_response("cup/enrollment_verification.html", {'form': form, 's_enrollments': session_enrollments}, context_instance=RequestContext(request))

Rendering s_enrollmentsin a list works well in template, but the multiple selection widget is empty. I've tried also with:

form = EnrollmentVerificationForm(initial={'enrollments': request.session["enrollments"]})

Neither approach results in a populated widget, even if same data rendered as a list works fine. There's probably somewhere my thinking is twisted. Any ideas?

hhuttunen
  • 57
  • 5
  • 1
    Just wondering but isn't there a better way of doing this? Why would you not store the enrollment information in your Enrollment model and add a "verified" BooleanField to that model? Your EnrollmentVerification view (or form, for that matter) could handle the setting of that property and that view would only need the id of the Enrollment object saved earlier on in the process. – Mathieu Dhondt May 15 '15 at 07:11
  • There might be a better way to do this, sure. But what happens in the view prior is that a search is performed where user's input is compared against Enrollments that match criteria. Those results are then shown in this view and user can verify them. This is due to project circumstances: the enrollment records come from an external source and this is part of linking the user to his enrollment by information only the user knows. I am open to a better pattern than this. – hhuttunen May 15 '15 at 10:35
  • Am I right when I describe it as follows: a user inputs something whereupon a list of possible Enrollments is presented. From that list, the user selects the Enrollments he wants? – Mathieu Dhondt May 15 '15 at 14:38

0 Answers0