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 %}
<tr class="{% cycle odd,even %}">
<td>{{ input }}</td>
<td>{{ r.user.get_full_name }}</td>
<td>{{ r.user.email }}</td>
<td>{{ r.user.get_profile.mobile_number }}</td>
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 [email protected]
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
-~----------~----~----~----~------~----~------~--~---