Opened 2 years ago

Closed 2 years ago

#29137 closed Cleanup/optimization (wontfix)

ModelForm, Generic Views and Generic Edit Views Custom Layout Simplification

Reported by: Spleeding1 Owned by: nobody
Component: Forms Version: 2.0
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no


I'm trying to make a customer form linked to a database(ModelForm) that on the screen would look like:

<fieldset name> Customer Information </fieldset name>(not actual html)
First_Name  Last_Name  MI
City  State  Zip_Code

These forms currently give you these html options: as "paragraph", as "list", as "table", which don't fit my layout. The text input boxes are also all the same size. To manually render the template requires a lot of html coding, adding labels etc.

The (admin.ModelAdmin) "fieldsets" already does this in the admin site. Is there a way of implementing this in these views?
Some options to consider: (ModelForm example)

class CustomerForm(ModelForm):
    class Meta:
        model = Customer
        fieldsets = [
            ('Name and Address', {'fields' : [ ('first_name', 'last_name', 'mi'),
                                                                    ('city', 'state', 'zip_code')
           ('Phone and Email', {'fields' : [ #(etc...)

And be able to customize:
" 'classes' : " or you could give it a css or javascript class and put it in your static file:

('Name and Address', {'fields' ('class' : ['name_field'], 'classes' : ['collapse'] ): [ ('first_name', (etc...)

And finally, make text input boxes the same "size" as the "max_length=" setting for the form or model.

Maybe there is an easy way to do all of this and I just couldn't find it in the documentation. If so, please let me know, and sorry.

Change History (1)

comment:1 Changed 2 years ago by Tim Graham

Resolution: wontfix
Status: newclosed

The ability to define fieldsets on forms is a duplicate of #6630 (closed as wontfix).

Regarding automatically changing input boxes size based on max_length -- that would be a rather disruptive change and not something that everyone would want. You could write a mixin for your forms to accomplish that.

Note: See TracTickets for help on using tickets.
Back to Top