custom width of char fields in admin

974 views
Skip to first unread message

Andre Meyer

unread,
Aug 7, 2008, 9:24:01 AM8/7/08
to django-users
hi all

maybe it's trivial, but i cannot find it anywhere:

how can the width of the text field be set for rendering in the admin interface.

suppose, you have a

title = models.CharField(max_length = 512)

and want to display more than what is shown in the standard fixed-width text input field.

using classes does not seem to work. what else? what about about TextField?

thanks
andré
(using latest trunk)

Daniel Roseman

unread,
Aug 7, 2008, 11:10:43 AM8/7/08
to Django users
I posted here on how to do this the other day:
http://groups.google.com/group/django-users/msg/00fab3dfecf3e5f0

--
DR.

Andre Meyer

unread,
Aug 7, 2008, 12:20:32 PM8/7/08
to django...@googlegroups.com
hi Daniel

great, will check it out tomorrow!

thanks a lot
André

Andre Meyer

unread,
Aug 8, 2008, 5:56:48 AM8/8/08
to django...@googlegroups.com
hi Daniel

so, it looks like i'm getting there, but there is one problem: do i really need to specify all the fields in the form and not just the one i want to customise? is there a way to inherit the rest of the fields from a ModelForm instance?

thanks
André


On Thu, Aug 7, 2008 at 5:10 PM, Daniel Roseman <roseman...@googlemail.com> wrote:

Daniel Roseman

unread,
Aug 8, 2008, 6:02:17 AM8/8/08
to Django users
On Aug 8, 10:56 am, "Andre Meyer" <andre.p.me...@gmail.com> wrote:
> hi Daniel
>
> so, it looks like i'm getting there, but there is one problem: do i really
> need to specify all the fields in the form and not just the one i want to
> customise? is there a way to inherit the rest of the fields from a ModelForm
> instance?
>
> thanks
> André

You don't need to specify them all, just the one you want to
customise. The others are automatically picked up from the model
itself. You might need to add the Meta inner class, as below (although
I thought this would be picked up from the ModelAdmin instance).

class MyAdminForm(forms.ModelForm):
mytextfield =
forms.CharField(widget=forms.TextInput(attrs={'size': 35})

class Meta:
model = MyModel


--
DR.

Andre Meyer

unread,
Aug 8, 2008, 6:05:24 AM8/8/08
to django...@googlegroups.com
hi Daniel

excellent: Meta is indeed required. it works now.

thanks a lot!
André
Reply all
Reply to author
Forward
0 new messages