>From my experience, max_length is not taken into account when you override model field in form field. In this case I don't know of any trivial way to read other field properties from model description.
Regards, Reinis On 20 okt., 17:54, Karen Tracey <kmtra...@gmail.com> wrote: > On Thu, Oct 15, 2009 at 12:30 PM, Gerard <lijss...@gp-net.nl> wrote: > > > Hi All, > > > It seems the max_lenght from the model definition is not respected > > thoughout > > the form that's created when using Modelform. > > > company_name = models.CharField(max_length=75) > > > Is this correct or am I missing something? > > This is not correct. For this model: > > class Tag(models.Model): > name = models.CharField(max_length=4) > > I see max_length being respected in the corresponding ModelForm: > > Python 2.5.2 (r252:60911, Oct 5 2008, 19:24:49) > [GCC 4.3.2] on linux2 > Type "help", "copyright", "credits" or "license" for more information. > (InteractiveConsole)>>> from ttt.models import Tag > >>> from django import forms > >>> class TForm(forms.ModelForm): > > ... class Meta: > ... model = Tag > ...>>> tf = TForm({'name':'Too long'}) > >>> tf.is_valid() > False > >>> tf.errors > > {'name': [u'Ensure this value has at most 4 characters (it has 8).']} > > >>> quit() > > What exactly did you try that led you to the conclusion that max_length is > not respected by ModelForms? > > Karen --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---