Re: Check box form
Thanks for all the help, I am still using some oldforms because i picked up this project from someone else, so thanks for the html work around. I will keep the newforms method in mind as well when an update rolls around. Again, this was a great help. Jacob On Oct 17, 5:30 pm, rskm1 <[EMAIL PROTECTED]> wrote: > On Oct 17, 1:52 pm, jacoberg2 <[EMAIL PROTECTED]> wrote: > > > I am trying to create a checkbox form so that the user can delete a > > large number of > > registrations at once. I am wondering how I should set up the view in > > order to deal with > > the incoming data. Any suggestions? > > The template can generate its own HTML easily enough without using a > forms.Form, e.g. > > > {% for t in thingylist %} > > {{ t.longname|escape }} > {% endfor %} > > > Then, when you're processing the POST form data, it's absolutely vital > that you call the POST.getlist('thingies') method rather than just > dereferencing POST['thingies'] ! > > if httpreq.POST.has_key('thingies'): > selectedthingies = httpreq.POST.getlist('thingies') > > I struggled with that for quite a while when I made my first checkbox > form in Django; I was expecting a list or tuple to be right there in > the POST for me to grab directly. But nope, you gotta use the > getlist() method. --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Re: Check box form
Hi Jacob, I had a similar situation. The key points that I wanted were: 1. Still use a normal Django newform that can validate itself etc. 2. Control of HTML remains in the template. The way I went about it was to: 1. Create a new form, say ManageRegistrationsForm that takes a result- set of registrations in the constructor and creates a checkbox field for each registration: class ManageRegistrationsForm(forms.Form): """Manages registrations with checkbox for each""" def __init__(self, registrations,*args,**kwargs): super(ManageRegistrationsForm,self).__init__(*args,**kwargs) # Now add a checkbox for each registration self.registrations = registrations for r in registrations: self.fields[str(r.user.id)] = forms.BooleanField( label=r.user.get_full_name(), required=False ) And then, 2. Define another member function of the form that returns a list of tuples (input field, registration): def get_inputs_with_regos(self): """ Returns a list of tuples (input, registration) for the form """ from django.newforms.forms import BoundField return [ ( BoundField(self, self.fields[str(r.user.id)], str(r.user.id)), r ) for r in self.registrations ] And finally, that allows you to do the following in the template: {% for input, r in form.get_inputs_with_regos %} {{ input }} {{ r.user.get_full_name }} {{ r.user.email }} {{ r.user.get_profile.mobile_number }} etc. And you can then add your normal form clean methods etc. for your form validation. Hope that helps. -Michael On Oct 18, 4:52 am, jacoberg2 <[EMAIL PROTECTED]> wrote: > Hey, > I am trying to create a checkbox form so that the user can delete a > large number of > registrations at once. I am wondering how I should set up the view in > order to deal with > the incoming data. Any suggestions? Thanks for any help i can get. > > Jacob --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Re: Check box form
On Oct 17, 1:52 pm, jacoberg2 <[EMAIL PROTECTED]> wrote: > I am trying to create a checkbox form so that the user can delete a > large number of > registrations at once. I am wondering how I should set up the view in > order to deal with > the incoming data. Any suggestions? The template can generate its own HTML easily enough without using a forms.Form, e.g. {% for t in thingylist %} {{ t.longname|escape }} {% endfor %} Then, when you're processing the POST form data, it's absolutely vital that you call the POST.getlist('thingies') method rather than just dereferencing POST['thingies'] ! if httpreq.POST.has_key('thingies'): selectedthingies = httpreq.POST.getlist('thingies') I struggled with that for quite a while when I made my first checkbox form in Django; I was expecting a list or tuple to be right there in the POST for me to grab directly. But nope, you gotta use the getlist() method. --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---