The Great Magnet. What a fool I was to defy him.

Django — Admin Inline Styling / Widget Attrs / Overriding Widgets

September 14, 2009 · Leave a Comment

Quickly style all of your inlines with formfield_for_dbfield

class PersonInline(admin.TabularInline):
	model = Person
	extra = 6
	def formfield_for_dbfield(self, db_field, **kwargs):
		attrs = { 'size': 15 }
		if db_field.attname == 'interest_level':
			attrs = { 'size': 2 }
		kwargs['widget'] = forms.TextInput(attrs=attrs)
		return super(PersonInline, self).formfield_for_dbfield(db_field,**kwargs)

I see this used for things like custom widgets, ReadOnlyWidget, ColoredWidget, etc, but I wanted a quick and dirty(?) way to fit more fields on my inlines, since the admin just overflows.

Categories: Life

0 responses so far ↓

  • There are no comments yet...Kick things off by filling out the form below.

Leave a Comment