Skip to content

Overriding and Extending Form Fields #285

@BrettMeirhofer

Description

@BrettMeirhofer

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions