Re: 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? I'm not sure that I understand the question but this is how I create new fields self.fields['ticket_%s' % ticket['id']] = forms.IntegerField(label = '', initial = 0, min_value = 0, max_value = self._max_tickets_count) and there are validation rules - integer value from 0 to _max_tickets_count On Feb 15, 9:24 pm, Mike Ramirezwrote: > 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 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-fiel... > > -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 -- 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 django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: Django Templates: Form field name as variable?
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 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 -- 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 django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: Django Templates: Form field name as variable?
Thank you very much for you answer I prefer to use validation that form class provides for me... I tried to use 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 -- 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 django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: Django Templates: Form field name as variable?
On Monday, February 14, 2011 07:00:38 am ju wrote: > How can I make this loop to print form fields where is the > value of ticket.id? > > {% for ticket in zone.tickets %} > {{ ticket.id }}: {{ form.ticket_count_ }} > {% endfor %} > > So the output to be something like this... > > 1: > 10: > 12: > 3: You can create a loop that creates these fields automagically. {% for ticket in zone.tickets %} {{ 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_XXX 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_XX, 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. -- 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 django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Django Templates: Form field name as variable?
How can I make this loop to print form fields where is the value of ticket.id? {% for ticket in zone.tickets %} {{ ticket.id }}: {{ form.ticket_count_ }} {% endfor %} So the output to be something like this... 1: 10: 12: 3: -- 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 django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.