Re: maxlength in the Admin site

2006-04-25 Thread ChaosKCW

Sweet, thanks alot. A welcome addition.


--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users
-~--~~~~--~~--~--~---



Re: maxlength in the Admin site

2006-04-20 Thread argus

Well, for better or worse I submitted a ticket with my modded
fields.py, based off the latest SVN trunk:
http://code.djangoproject.com/ticket/1665


--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users
-~--~~~~--~~--~--~---



Re: maxlength in the Admin site

2006-04-20 Thread argus

Actually, it was really easy.  As in "four lines" easy.  I haven't done
extensive testing with it, but a quick run through seems to demonstrate
that it does what I want it to do.

Best of all, you only have to modify one file -- core/meta/fields.py:
1) Add a new param "length=None" to the __init__ declaration for the
base Field class, around lines 105-111

2) in the __init__ method, add a line to use the new param:
"self.length = length" (I added this right after the line that grabs
the maxlength param, cause it made sense to me there)

3) tweak the get_manipulator_fields method around line 230 to make use
of the new "self.length" attribute.  Add the following lines (with
corrected indenting, of course):

if self.length:
params['length'] = self.length

You should end up with something like:

if self.maxlength and not self.choices:
params['maxlength'] = self.maxlength
if self.length:
params['length'] = self.length


That's it.  Now you can use a "length" param in your model
declarations, like:
class Poll(meta.Model):
question = meta.CharField(maxlength=200, length=4)

The result is what you'd expect: the resulting HTML form field used in
the admin interface has its "size" attribute set to "4".


--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users
-~--~~~~--~~--~--~---



Re: maxlength in the Admin site

2006-04-19 Thread Joseph Kocherhans

On 4/19/06, Joseph Kocherhans <[EMAIL PROTECTED]> wrote:
> On 4/19/06, argus <[EMAIL PROTECTED]> wrote:
> >
> > Is there any reason that there's not a way to specify/override the size
> > of the form field that gets used in templates (separately from what
> > gets used in the admin interface)?  I can't think of one, and it's been
> > something of a thorn in my side recently, so I figured I'd ask :)  I'm
> > reluctant to hack into the Django source for something so trivial, but
> > I'm getting closer to doing so..
>
> As lame as it sounds, you're right. There isn't a clean way to do it.
> I know it was discussed on the list not too long ago (or maybe it was
> django-dev), but I don't think much came out of it. Here's a link
> anyhow:
>
> http://groups.google.com/group/django-users/browse_frm/thread/4f6e2e0c936dcca5/7e7c0a7b2b168bd5?tvc=1=field+length#7e7c0a7b2b168bd5

Wow... that's this thread! (Time for me to sleep.)

> That said, if you can come up with a nice way to do this, patches and
> ideas are welcome.

This still applies :)

--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users
-~--~~~~--~~--~--~---



Re: maxlength in the Admin site

2006-04-19 Thread Joseph Kocherhans

On 4/19/06, argus <[EMAIL PROTECTED]> wrote:
>
> Is there any reason that there's not a way to specify/override the size
> of the form field that gets used in templates (separately from what
> gets used in the admin interface)?  I can't think of one, and it's been
> something of a thorn in my side recently, so I figured I'd ask :)  I'm
> reluctant to hack into the Django source for something so trivial, but
> I'm getting closer to doing so..

As lame as it sounds, you're right. There isn't a clean way to do it.
I know it was discussed on the list not too long ago (or maybe it was
django-dev), but I don't think much came out of it. Here's a link
anyhow:

http://groups.google.com/group/django-users/browse_frm/thread/4f6e2e0c936dcca5/7e7c0a7b2b168bd5?tvc=1=field+length#7e7c0a7b2b168bd5

That said, if you can come up with a nice way to do this, patches and
ideas are welcome.

Joseph

--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users
-~--~~~~--~~--~--~---



Re: maxlength in the Admin site

2006-04-19 Thread argus

Is there any reason that there's not a way to specify/override the size
of the form field that gets used in templates (separately from what
gets used in the admin interface)?  I can't think of one, and it's been
something of a thorn in my side recently, so I figured I'd ask :)  I'm
reluctant to hack into the Django source for something so trivial, but
I'm getting closer to doing so..


--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users
-~--~~~~--~~--~--~---



Re: maxlength in the Admin site

2006-03-23 Thread ChaosKCW

Hi

If the form element is set correctly I have to question why it saved
more than 3 characters to the DB and then retrieved those same
characters back again. I would have to dig deeper to see exactly what
is going on which is why I posted the question first, under the idea
that other people have want the same restrictions.

When i have time I will investigate further.

Thanks,

C


--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users
-~--~~~~--~~--~--~---



Re: maxlength in the Admin site

2006-03-22 Thread Adrian Holovaty

On 3/21/06, ChaosKCW <[EMAIL PROTECTED]> wrote:
> I am wondering what I need to do in order to get the admin site to
> enforce the maxlength property. I am using the MR Branch.
>
> I have a model with a CharField where maxlength=3. I goto in admin. It
> shows a huge box ie way more than 3 charcaaters, allows you to enter
> more than 3 characters and doesnt error when you save more than 3
> characters.
>
> This seems strange to me. Any suggestions ?

Hi Chaos,

CharFields are represented in the admin with a fixed length. The
"maxlength" property on those boxes is set correctly, but the size of
the actual form element is hard-coded.

This is probably worth changing, because you're right to note that
it's silly for a two-character field to have a long input element. But
we can't just blindly set the length of the field to the maxlength,
because maxlength=200 would result in a horribly long field. There
would have to be some sort of upper limit.

Adrian

--
Adrian Holovaty
holovaty.com | djangoproject.com

--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users
-~--~~~~--~~--~--~---



maxlength in the Admin site

2006-03-21 Thread ChaosKCW

Hi

I am wondering what I need to do in order to get the admin site to
enforce the maxlength property. I am using the MR Branch.

I have a model with a CharField where maxlength=3. I goto in admin. It
shows a huge box ie way more than 3 charcaaters, allows you to enter
more than 3 characters and doesnt error when you save more than 3
characters. 

This seems strange to me. Any suggestions ? 

Thanks,

C


--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users
-~--~~~~--~~--~--~---