#35464: Fieldsets defined for TabularInlines are ignored ------------------------------------------------+------------------------ Reporter: Natalia Bidart | Owner: nobody Type: Cleanup/optimization | Status: new Component: contrib.admin | Version: dev Severity: Normal | Keywords: Triage Stage: Unreviewed | Has patch: 0 Needs documentation: 0 | Needs tests: 0 Patch needs improvement: 0 | Easy pickings: 0 UI/UX: 0 | ------------------------------------------------+------------------------ Following the review of the PR solving #35189 and the analysis done in #35456, I found out that when defining an admin model with a `TabularInline` instance which defines `fieldsets`, those `fieldsets` are "ignored" in the UI (in terms of actually using a fieldset element, the content is shown). Furthermore, if the `fieldsets` include the `collapse` CSS class, nothing changes in the UI and there is not way of having collapsible fieldsets inside `TabularInline`s. See attached screenshots and some example models down below.
Regarding how to fix this, I see two options: 1. Discuss with the accessibility plan whether there is a way to structure HTML to have "collapsible fieldsets" inside a tabular context, or 2. Explicitly document that `fieldsets` make no sense for `TabularInline`. The current docs imply this setup is valid: > InlineModelAdmin.classes > A list or tuple containing extra CSS classes to apply to the fieldset that is rendered for the inlines. Defaults to None. As with classes configured in fieldsets, inlines with a collapse class will be initially collapsed and their header will have a small “show” link. Example modes and admin models: * models.py {{{#!python from django.db import models from django.utils.timezone import now class Book(models.Model): title = models.CharField(max_length=100) author = models.CharField(max_length=100) publisher = models.CharField(max_length=100) creation_date = models.DateField(default=now) update_date = models.DateField(default=now) publication_date = models.DateField(default=now) def __str__(self): return self.title class Cover(models.Model): book = models.ForeignKey(Book, on_delete=models.CASCADE) image = models.CharField(max_length=100) title = models.CharField(max_length=100) description = models.TextField() creation_date = models.DateField(default=now) update_date = models.DateField(default=now) updated_by = models.CharField(max_length=100) }}} * admin.py {{{#!python from django.db import models from django.contrib import admin from .models import Book, Cover class CoverInlineMixin: model = Cover extra = 2 fieldsets = ( (None, {"fields": ("image", "title")}), ("Details", { "fields": ("description", "creation_date"), "classes": ("collapse",), }), ("Details", { "fields": ("update_date", "updated_by"), "classes": ("collapse",), }), ) class CoverTabularInline(CoverInlineMixin, admin.TabularInline): pass class CoverStackedInline(CoverInlineMixin, admin.StackedInline): pass class BookAdmin(admin.ModelAdmin): list_display = ("title", "author", "publisher","publication_date") search_fields = ("title", "author") list_filter = ("author", "publication_date") fieldsets = ( (None, { "fields": ("title", "author") }), ("Advanced options", { "classes": ("collapse",), "fields": ("publisher", "publication_date",) }), ("Advanced options", { "classes": ("collapse",), "fields": ("creation_date", "update_date",) }), ) inlines = [ CoverTabularInline, CoverStackedInline, ] admin.site.register(Book, BookAdmin) }}} -- Ticket URL: <https://code.djangoproject.com/ticket/35464> 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 django-updates+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/django-updates/0107018f8700654d-0f3e08f7-3f75-400a-b7ec-78b37db2ebc0-000000%40eu-central-1.amazonses.com.