> I am having a bit of trouble posting checked items from a form to my
> view so I can save it to a database table.
> The data in the form are information that has been stripped from a
> file so there is no database link/referencing there.
>
> What I have done half works as it does post my selected items and
> saves it to the database but it only posts the last item in the list
> rather than the other items I have selected.
>
> It might just be me looking at this too long or I'm doing something
> horribly wrong.
>
> Any help would be great
>
> Here is a snippet of my code that I am having problems with
>
> --Html form-
> {% for choice in currentproject %}
>
>
>
> Check Name:
> Variable:
> Error Message:
> Range:
> Comments:
> Select:
>
>
> {% if checkstore %}
> {% for a,b,c in checkstore %}
>
>readonly="True"
> name="chname" value="{{a}}"/>
>readonly="True"
> name="clflag" value="{{b}}"/>
>readonly="True"
> name="ermsg" value="{{c}}"/>
>
>
>
>
>
>
>
>
>
>
>
>
> {% endfor %}
This will result in several checkboxes, all with the same value (well,
actually, no value at all); how are you going to distinguish between
the different checkboxes?
Did you check the actualy rendered HTML, and the POST variable you get
returned from this form?
>
> {% endif %}
>
>
>
>
>
>
> {% endfor %}
>
> ---view
>
> if request.POST:
> selected1 = Project.objects.get(id=project_id)
>
> try:
> selectedch = request.POST['selectedcheck']
You'll only get the last value in this way. See the docs for
QueryDict:
http://www.djangoproject.com/documentation/request_response/#querydict-objects
>
> except:
> #stops any empty POST errors
> qset = (Q(projectid = project_id))
> results = StudyChecksFinal.objects.filter(qset)
> return render_to_response('selected.html', {
> 'results': results,
> 'currentproject': currentproject,
> 'theuser' : theuser,
> })
>
> chname = request.POST['chname']
> clflag = request.POST['clflag']
> ermsg = request.POST['ermsg']
>
> try:
> range2 = request.POST['rangech']
> except:
> range2 = 'None'
> try:
> comments = request.POST['comment']
> except:
> comments = 'None'
> if range2 == 'None':
> range2 = ''
> if comments == 'None':
> comments = ''
>
> new = StudyChecksFinal(projectid=selected1, checkname='%s' %chname,
> clinflag='%s' %clflag, errmsg='%s' %ermsg, checkrange='%s' %range2,
> comments='%s' %comments)
> new.save()
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---