Hello, I don't know if this was debated before, but I think the behavior of 
Collapsed fieldsets 
<https://docs.djangoproject.com/en/2.0/ref/contrib/admin/#django.contrib.admin.ModelAdmin.fieldsets>
 
on Django Admin could confuse some devs. Here is the example:

Consider the django.contrib.auth.admin.UserAdmin.fieldsets 
<https://github.com/django/django/blob/2.0.1/django/contrib/auth/admin.py#L44>
.

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

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


<https://lh3.googleusercontent.com/--H8XzcIArmw/Wm5AqkcajHI/AAAAAAAAHRk/ODiGh2tUWj0uGUHDrdPmHdCYl8tmM35tACLcBGAs/s1600/Screen%2BShot%2B2018-01-28%2Bat%2B17.44.04.png>

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:

<https://lh3.googleusercontent.com/-e61pmBlspUE/Wm5CcUFKgvI/AAAAAAAAHRw/HHdTZ4Idqro8IvL6xvDzSFrSYbDUaJEagCLcBGAs/s1600/Screen%2BShot%2B2018-01-28%2Bat%2B17.43.03.png>fieldsets
 
= (
    (None, {'classes': ('collapse',), 'fields': ('first_name', 'last_name', 
'email')}),
)

And the result would be:

<https://lh3.googleusercontent.com/-nHOl2W06vAg/Wm5N3HetX_I/AAAAAAAAHSE/OSdiFT5TaMEGpKen_ifUpvD9GOUf8uB7QCLcBGAs/s1600/Screen%2BShot%2B2018-01-28%2Bat%2B17.43.03.png>


Almost the same, but if you look here 
<https://github.com/django/django/blob/2.0.1/django/contrib/admin/templates/admin/includes/fieldset.html#L2>
 
you'll see Django won't render the *h2 block* if there's no *fieldset.name*, 
and if you look here 
<https://github.com/django/django/blob/2.0.1/django/contrib/admin/static/admin/js/collapse.js#L9>,
 
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?

-- 
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+unsubscr...@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.

Reply via email to