Re: Accessing model field validators from within form template
Please see below.
> Why do you use MaxLengthValidator instead of max_length property?
max_length does not work for models.TextField
> What are you using those values for? Couldn't it be a possibility to
> use help_text attribute?
It won't be DRY to repeat the value both as a parameter to the
validator and in the help text. I would like to display the max length
value using a generic template.
Cheers,
omat
> On Aug 18, 3:41 pm, omat <o...@gezgin.com> wrote:
>
>
>
> > Hi,
>
> > In my generic form template, if a CharField has a max_length
> > attribute, I display that beside the form field:
>
> > {% if field.field.max_length %}
> > Max. {{ field.field.max_length }} char.
> > {% endif %}
>
> > I want to do the same for TextFields, where max_length is not used,
> > but the max limit is set by a validator like that in the model:
>
> > class Entry(models.Model):
> > ...
> > body = models.TextField(validators=[MaxLengthValidator(1000)])
>
> > For ModelForm, is it possible to access the validators' max value from
> > within the templates similar to this:
>
> > {{ field.validators[0].max_length }}
>
> > Cheers,
> > omat
--
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+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home