Mario Orlandi's Snippets

16/12/2011

set Django Form Textatea size

Filed under: Uncategorized — Tags: , — morlandi @ 11:59
class CourseAttachmentInline(admin.TabularInline):
    model = CourseAttachment
    extra = 1

    def formfield_for_dbfield(self, db_field, **kwargs):
        field = super(CourseAttachmentInline, self).formfield_for_dbfield(db_field, **kwargs)
        if db_field.name in ('subtitle',):
            #field.widget.attrs['rows'] = 3
            #field.widget.attrs['cols'] = 20
            field.widget.attrs = {'rows': 3, 'cols': 50}
        return field

or


class CourseAttachmentInline(admin.TabularInline):
    model = CourseAttachment
    extra = 1

    def formfield_for_dbfield(self, db_field, **kwargs):
        if db_field.name in ('subtitle',):
            return forms.CharField(widget=forms.Textarea(
                attrs={'cols': 50, 'rows': 3},
            ))
        return super(CourseAttachmentInline, self).formfield_for_dbfield(db_field, **kwargs)
Advertisement

Leave a Comment »

No comments yet.

RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Theme: Silver is the New Black. Blog at WordPress.com.

Follow

Get every new post delivered to your Inbox.