#25702: Port ModelAdmin.fieldset to BaseForm
-------------------------------------+-------------------------------------
Reporter: Psycojoker | Owner: nobody
Type: New feature | Status: new
Component: Forms | Version: master
Severity: Normal | Resolution:
Keywords: form modeladmin | Triage Stage:
layout admininterface | Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Psycojoker):
* needs_better_patch: => 0
* needs_tests: => 0
* needs_docs: => 0
Old description:
> In the admin interface it is possible to control the admin forms layout
> using the //fieldset// attribute. This feature is described here:
> https://docs.djangoproject.com/en/1.8/ref/contrib/admin/#django.contrib.admin.ModelAdmin.fieldsets
>
> Here is the example from the documentation (modified to display the
> feature that allows to display multiple fields in the same line):
>
> {{{#!python
> from django.contrib import admin
>
> class FlatPageAdmin(admin.ModelAdmin):
> fieldsets = (
> (None, {
> 'fields': (('url', 'title'), ('content', 'sites'))
> }),
> ('Advanced options', {
> 'classes': ('collapse',),
> 'fields': ('enable_comments', 'registration_required',
> 'template_name')
> }),
> )
> }}}
>
> The idea of this feature would be to port this exact behavior to the
> standard django forms. Taking the first form example from the
> documentation, this could look like this:
>
> {{{#!python
> from django import forms
>
> class ContactForm(forms.Form):
> subject = forms.CharField(max_length=100)
> message = forms.CharField(widget=forms.Textarea)
> sender = forms.EmailField()
> cc_myself = forms.BooleanField(required=False)
>
> fieldset = (
> (None, {
> "fields": (('sender', 'cc_myself'),),
> }),
> ("Content", {
> "fields": ("subject", "message"),
> }),
> )
> }}}
>
> Currently, there is no way to modify the form layout beside the field
> order. This is very frustrating because this mean that if you want modify
> the layout of a form, you need to explode it totally to do that or you
> need to use another project (like django-crispy-forms [#point1 (1)] or
> another one).
>
> While not going to all the extend of what django-cripsy-forms or another
> project is doing, //fieldset// is an already known and used convention
> accross the django project and allowing it in standard forms seems like a
> natural and intuitive choice.
>
> [=#point1 (1)] http://django-crispy-
> forms.readthedocs.org/en/latest/layouts.html
New description:
In the admin interface it is possible to control the admin forms layout
using the //fieldset// attribute. This feature is described here:
https://docs.djangoproject.com/en/1.8/ref/contrib/admin/#django.contrib.admin.ModelAdmin.fieldsets
Here is the example from the documentation (modified to display the
feature that allows to display multiple fields in the same line):
{{{#!python
from django.contrib import admin
class FlatPageAdmin(admin.ModelAdmin):
fieldsets = (
(None, {
'fields': (('url', 'title'), ('content', 'sites'))
}),
('Advanced options', {
'classes': ('collapse',),
'fields': ('enable_comments', 'registration_required',
'template_name')
}),
)
}}}
The idea of this feature would be to port this exact behavior to the
standard django forms. Taking the first form example from the
documentation, this could look like this:
{{{#!python
from django import forms
class ContactForm(forms.Form):
subject = forms.CharField(max_length=100)
message = forms.CharField(widget=forms.Textarea)
sender = forms.EmailField()
cc_myself = forms.BooleanField(required=False)
fieldset = (
(None, {
"fields": (('sender', 'cc_myself'),),
}),
("Content", {
"fields": ("subject", "message"),
}),
)
}}}
Currently, there is no way to modify the form layout beside the field
order. This is very frustrating because this mean that if you want modify
the layout of a form, you need to explode it totally to do that or you
need to use another project (like django-crispy-forms [#point1 (1)] or
another one).
While not going to all the extend of what django-cripsy-forms or another
project is doing, //fieldset// is an already known and used convention
accross the django project and allowing it in standard forms seems like a
natural and intuitive choice.
Regarding the API, I'm wondering if puting the //fieldset// attribute in
the //Meta// class doesn't make more sens since it is already used (only
for the //ModelForm//?) to specify options and this will avoid a conflict
with currently existing fields named //fieldset//.
This would look like this:
{{{#!python
from django import forms
class ContactForm(forms.Form):
subject = forms.CharField(max_length=100)
message = forms.CharField(widget=forms.Textarea)
sender = forms.EmailField()
cc_myself = forms.BooleanField(required=False)
class Meta:
fieldset = (
(None, {
"fields": (('sender', 'cc_myself'),),
}),
("Content", {
"fields": ("subject", "message"),
}),
)
}}}
[=#point1 (1)] http://django-crispy-
forms.readthedocs.org/en/latest/layouts.html
--
--
Ticket URL: <https://code.djangoproject.com/ticket/25702#comment:1>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/068.9902b618b2b69f592d1b4cf3f4742980%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.