Behavior of ModelAdmin.fieldsets with 'classes': ('collapse',) when fieldset name is None.

1,260 views
Skip to first unread message

Douglas Miranda

unread,
Jan 28, 2018, 5:46:46 PM1/28/18
to Django developers (Contributions to Django itself)

Hello, I don't know if this was debated before, but I think the behavior of Collapsed fieldsets on Django Admin could confuse some devs. Here is the example:


If I add 'classes': ('collapse',) to field option

fieldsets = (
   
# ...
   
(_('Personal info'), {'classes': ('collapse',), 'fields': ('first_name', 'last_name', 'email')}),
   
# ...
)



As you can see the fieldset name is _('Personal info'), so everything is as expected Personal Info (Show)

But I can create fieldsets without fieldset name, like this:

fieldsets = (
   
(None, {'classes': ('collapse',), 'fields': ('first_name', 'last_name', 'email')}),
)

And the result would be:



Almost the same, but if you look here you'll see Django won't render the h2 block if there's no fieldset.name, and if you look here, this javascript code looks for the h2 tag to add the "Show" link to collapsed fieldsets.


So that's it, If someone creates a collapsible fieldset without fieldset name, Django just doesn't show the fieldset at all.

It's not something difficult to fix, but I would like to hear from you guys.

* If you agree that it needs to be fixed, just showing the (Show) link, would suffice?

* Or warn the user about using collapse class without a fieldset name?

Adam Johnson

unread,
Jan 29, 2018, 12:24:30 PM1/29/18
to django-d...@googlegroups.com
* If you agree that it needs to be fixed, just showing the (Show) link, would suffice?

+1 from me, seems like the straightforward solution 

--
You received this message because you are subscribed to the Google Groups "Django developers (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-developers+unsubscribe@googlegroups.com.
To post to this group, send email to django-developers@googlegroups.com.
Visit this group at https://groups.google.com/group/django-developers.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-developers/c014e145-edf3-4639-8112-801c365e7ce3%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Adam
Reply all
Reply to author
Forward
0 new messages