How to change widgets for admin site?

23 views
Skip to first unread message

Gchorn

unread,
Apr 16, 2012, 1:24:54 AM4/16/12
to Django users
Hello, I'm trying to create a blog site using Django (with "Post" as
my main model and "text" as the attribute corresponding to the main
body of text for each post). On the admin page, when someone is
filling out fields to create a new blog post, I want the "text" entry
field to be larger than the default field for a CharField attribute.

In this part of the docs:

https://docs.djangoproject.com/en/1.4/ref/contrib/admin/

in the "ModelAdmin options" section, under "ModelAdmin.fieldsets",
there is an image of pretty much what I want--a set of text entry
fields, where one of the fields, named "Content", is much larger than
the others to make it easier for whoever uses the admin site to type
in larger amounts of text. However, there isn't any clear explanation
that I can find in this section about how to achieve this.

The closest thing I can find is a little ways further, there's a
section that says you can use "classes" as a field_options dictionary
key, and it mentions two classes defined by the default admin style
sheet (collapse and wide). I think I need to specify some kind of
class in this way, but I don't know where on my file system the
default admin style sheet is located in order to read it and see if
there are any classes there I can use.

Can anyone help with this? Is there a built-in CSS class that does
what I want, or do I need to write it myself? If the latter, can
anyone tell me where I should write it and where I need to reference
it so that it affects the admin site?

Marc Patermann

unread,
Apr 16, 2012, 4:51:58 AM4/16/12
to django...@googlegroups.com
Hi,

Gchorn schrieb (16.04.2012 07:24 Uhr):
> Hello, I'm trying to create a blog site using Django (with "Post" as
> my main model and "text" as the attribute corresponding to the main
> body of text for each post). On the admin page, when someone is
> filling out fields to create a new blog post, I want the "text" entry
> field to be larger than the default field for a CharField attribute.
>
> In this part of the docs:
>
> https://docs.djangoproject.com/en/1.4/ref/contrib/admin/

what you see in the admin interface is inherited form the model of the
corresponding object - like your blog post object.
I think you have to change the field length there.

https://docs.djangoproject.com/en/1.4/intro/tutorial01/


Marc

Guillaume Chorn

unread,
Apr 16, 2012, 8:24:43 AM4/16/12
to django...@googlegroups.com
Hi Marc,

Thanks for your reply.  Are you referring to the "max_length" element of my "text" CharField?  If so, I don't think this is the issue; I've set the max length to 10,000 characters which is quite long.  Also this setting does not change the size of the text input area relative to my other CharFields with much shorter max_length values (such as "title", which has a max length of only 1000).

cheers,
Guillaume



--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django...@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.


Daniel Roseman

unread,
Apr 16, 2012, 10:28:08 AM4/16/12
to django...@googlegroups.com
'content' in that model is a models.TextField, not models.CharField. TextFields by default render with the Textarea widget.
--
DR.

Guillaume Chorn

unread,
Apr 16, 2012, 11:38:51 AM4/16/12
to django...@googlegroups.com
Shoot! I was thinking that might be the case originally, but I must have overlooked TextField in the model field docs. Thanks!!!

I'm still curious though--how can I find out what all of the CSS classes are that are defined by the default admin style sheet (I guess I'm asking where this style sheet normally resides in a typical Django installation)?
--
You received this message because you are subscribed to the Google Groups "Django users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/django-users/-/7aPR5gfE6mYJ.

To post to this group, send email to django...@googlegroups.com.
To unsubscribe from this group, send email to django-users...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages