I have two forms named GoodAtForm and PaidForForm. What these do is as follows...
GoodAtFormTakes an input from a list inrequest.session['love']and presents it to the user.Then user is presented with a
CheckboXSelectMultiplefields so that users can select.After The form is submitted in the view, the user choices are then stored inside another list
request.session['good'].
4.Another Form named PaidForForm uses that list for further asking of questions from users using CheckBocSelectMultiple and the selections are from the list ```request.session['good'].
My problem is that I am unable to access output data inside the Forms to provide it to view.
Input is working fine when initialised. My forms renders Check Boxes from the given LOVE list but the problem is that Form is not providing output. It says
form = GoodAtForm(request.POST)
input_list = request.session['love']
'QueryDict' object has no attribute 'session'
This is my GoodAtForm
class GoodAtForm(forms.Form):
def __init__(self, request, *args, **kwargs):
super(GoodAtForm, self).__init__(*args, **kwargs)
input_list = request.session['love']
self.fields['good'] = forms.MultipleChoiceField(
label="Select Things You are Good At",
choices=[(c, c) for c in input_list],
widget=forms.CheckboxSelectMultiple
)
View For the GoodAtForm
def show_good_at(request):
if request.method == 'POST':
form = GoodAtForm(request.POST) #it is showing problem here. Throws an exception here
if form.is_valid():
if not request.session.get('good'):
request.session['good'] = []
request.session['good'] = form.cleaned_data['good']
return redirect('paid_for')
else:
form = GoodAtForm(request=request) #rendering form as usual from the list 'love'
return render(request, 'good_at_form.html', {'form':form})