django_reverse_admin icon indicating copy to clipboard operation
django_reverse_admin copied to clipboard

Overriding and Extending Form Fields

Open BrettMeirhofer opened this issue 4 years ago • 1 comments

When working with a reverse inline what is the best way to override form field properties? For example an Address model with a zip_code field being displayed as a Reverse Inline for a Customer Model. How would I go about getting the zip_code field reference in order to reduce the size of it's input box? The standard overriding get_form on the CustomerAdmin results in a keyerror.

def get_form(self, request, obj=None, **kwargs): form = super(CustomerAdmin, self).get_form(request, obj, **kwargs) form.base_fields['zip_code'].widget.attrs['style'] = 'width: 45em;' return form

BrettMeirhofer avatar Oct 27 '21 22:10 BrettMeirhofer

You can create a customized form and make the necessary adjustments to the widgets.

I documented this here.

gutierri avatar Apr 26 '24 00:04 gutierri