I am a newbie in django, and I need some examples on this code I am working on.
I have a textbox, and an output on the same template and this is the view for this:
def sessiontest(request):
a=request.session.get('a',{})
form=sform()
return render_to_response('cart.html',{'form':form,'a':a},context_instance=RequestContext(request))
and the view for processing the data is this :
def sessiontest2(request):
if request.method=="POST":
form=sform(request.POST)
if form.is_valid():
request.session['a']=form.cleaned_data["name"]
return HttpResponseRedirect(reverse(sessiontest))
It is working fine if i just need to store ONE value, but how do I allow my request.session['a'] to store multiple data everytime there is a new input such as {value1,value2,new_value,new_value}
? I need it to be in a format which I can display with a {% for i in a %}
loop in my templates and be used to filter my models.
This is just a test code, later on I will need to store my product_id in it and use it to filter my items in this way:
items=models.products.objects.filter(pk=request.session["a"])
Please give me some hints on how this could be done.