daniyalzade / django_reverse_admin

Django Reverse Admin
BSD 3-Clause "New" or "Revised" License
199 stars 54 forks source link

Overriding and Extending Form Fields #285

Open BrettMeirhofer opened 3 years ago

BrettMeirhofer commented 3 years ago

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

gutierri commented 6 months ago

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

I documented this here.