Gmail Calendar Documents Reader Web more »
Recently Visited Groups | Help | Sign in
Google Groups Home
DRY: max length not taken from Model.field when using ModelForm
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  5 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Gerard  
View profile  
 More options Oct 16, 2:30 am
From: Gerard <lijss...@gp-net.nl>
Date: Thu, 15 Oct 2009 18:30:53 +0200
Local: Fri, Oct 16 2009 2:30 am
Subject: DRY: max length not taken from Model.field when using ModelForm
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?
And while violating DRY is the Modelform definition the best place to put this?

It does seem to work for the form fields' label, which is taken from the
model fields' verbose name.

Thanx for any light on the subject

Regards,

Gerard.

--
self.url = www.gerardjp.com


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Karen Tracey  
View profile  
 More options Oct 21, 1:54 am
From: Karen Tracey <kmtra...@gmail.com>
Date: Tue, 20 Oct 2009 11:54:13 -0400
Local: Wed, Oct 21 2009 1:54 am
Subject: Re: DRY: max length not taken from Model.field when using ModelForm

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


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
fest  
View profile  
 More options Nov 8, 4:25 am
From: fest <hell...@gmail.com>
Date: Sat, 7 Nov 2009 09:25:38 -0800 (PST)
Local: Sun, Nov 8 2009 4:25 am
Subject: Re: DRY: max length not taken from Model.field when using ModelForm
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:


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Tomasz Zieliński  
View profile  
 More options Nov 8, 6:27 am
From: Tomasz Zieliński <tomasz.zielin...@pyconsultant.eu>
Date: Sat, 7 Nov 2009 11:27:24 -0800 (PST)
Local: Sun, Nov 8 2009 6:27 am
Subject: Re: DRY: max length not taken from Model.field when using ModelForm
On 7 Lis, 18:25, fest <hell...@gmail.com> wrote:

> From my experience, max_length is not taken into account when you
> override model field in form field.

This is (and was, when I first time faced it) quite obvious for me .
If ModelForm was modifying overridden fields, the whole concept
of overriding would be useless.

On the other hand it would be nice if we could write something like:

first_name = forms.CharField(max_length=copy_from_model)

--
Tomasz Zieliński
http://pyconsultant.eu


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
fest  
View profile  
 More options Nov 10, 4:53 am
From: fest <hell...@gmail.com>
Date: Mon, 9 Nov 2009 09:53:30 -0800 (PST)
Local: Tues, Nov 10 2009 4:53 am
Subject: Re: DRY: max length not taken from Model.field when using ModelForm
Tomasz, it was obvious for me too, however, I had defined a form,
which had some fields overridden, but some not- I was hoping that
options for fields that were not overridden were preserved, but due to
specific way admin interface handles forms, required class wasn't
added to my custom form fields. That's why I thought other field
options were not taken into account.

Reinis

On 7 nov., 21:27, Tomasz Zieliński <tomasz.zielin...@pyconsultant.eu>
wrote:


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »

Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2009 Google