You can create a loop that creates these fields automagically.
{% for ticket in zone.tickets %}
{{ ticket.id }} <input ... name="ticket_count_{{ ticket.id }}" />
{% endfor %}
in your view you can get it with:
ticket_name = "ticket_count_%s" %(ticket.id)
tc = request.POST[ticket_name]
# validate the data as an int, if the form class doesn't define
# ticket_count_XXXXXXX to clean it for you.
form = myForm
try:
ticket_count = int(tc)
except:
# set form errors.
form.errors = {ticket_name: "Invalid data inputed for ticket count"}
if not form.errors:
# now validate with the form data as normal, checking again for errors.
form.is_valid():
...
if your form class generates the ticket_count_XXXXXX, you can then just use the form api as normal, validate and clean then use form.cleaned_data, the form api won't really care if you generate the html or it does [1].
Mike
[1] http://docs.djangoproject.com/en/1.2/topics/forms/#customizing-the-form-template
--
patent:
A method of publicizing inventions so others can copy them.
On Tuesday, February 15, 2011 01:31:07 am ju wrote:
> Thank you very much for you answer
>
> I prefer to use validation that form class provides for me...
>
I do too.
> I tried to use <input ... name="ticket_count_{{ ticket.id }}" /> but
> the other problem that I have is that I can't get errors for each
> field of form :(
> .
> There is another solution that I decide to use:
> http://stackoverflow.com/questions/4993625/django-templates-form-field-name
> -as-variable
I like it too, but aren't you still stuck with validating it or are you applying a validator to each field you generate this way?
Mike
--
A physicist is an atom's way of knowing about atoms.
-- George Wald