[Django] #35464: Fieldsets defined for TabularInlines are ignored

16 views
Skip to first unread message

Django

unread,
May 17, 2024, 10:41:45 AMMay 17
to django-...@googlegroups.com
#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.

Django

unread,
May 17, 2024, 10:45:38 AMMay 17
to django-...@googlegroups.com
#35464: Fieldsets defined for TabularInlines are ignored
-------------------------------------+-------------------------------------
Reporter: Natalia Bidart | Owner: nobody
Type: | Status: new
Cleanup/optimization |
Component: contrib.admin | Version: dev
Severity: Normal | Resolution:
Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Natalia Bidart):

* Attachment "image-20240517-114532.png" added.

Django

unread,
May 17, 2024, 10:47:31 AMMay 17
to django-...@googlegroups.com
#35464: Fieldsets defined for TabularInlines are ignored
-------------------------------------+-------------------------------------
Reporter: Natalia Bidart | Owner: nobody
Type: | Status: new
Cleanup/optimization |
Component: contrib.admin | Version: dev
Severity: Normal | Resolution:
Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 1
-------------------------------------+-------------------------------------
Changes (by Natalia Bidart):

* cc: Marijke Luttekes, Thibaud Colas, Tom Carrick, Sarah Abderemane
(added)
* ui_ux: 0 => 1

--
Ticket URL: <https://code.djangoproject.com/ticket/35464#comment:1>

Django

unread,
May 17, 2024, 11:25:05 AMMay 17
to django-...@googlegroups.com
#35464: Fieldsets defined for TabularInlines are ignored
--------------------------------------+------------------------------------
Reporter: Natalia Bidart | Owner: nobody
Type: Cleanup/optimization | Status: new
Component: contrib.admin | Version: dev
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 1
--------------------------------------+------------------------------------
Changes (by Sarah Boyce):

* stage: Unreviewed => Accepted

Comment:

I think this is a little similar to #21353 where a note was added to
"description" but I think this note should be pulled out and generally be
stated for
[https://docs.djangoproject.com/en/5.0/ref/contrib/admin/#django.contrib.admin.ModelAdmin.fieldsets
TabularInlines]
I would vote option 2 and have a note 👍
--
Ticket URL: <https://code.djangoproject.com/ticket/35464#comment:2>

Django

unread,
May 18, 2024, 7:00:21 AMMay 18
to django-...@googlegroups.com
#35464: Fieldsets defined for TabularInlines are ignored
--------------------------------------+------------------------------------
Reporter: Natalia Bidart | Owner: nobody
Type: Cleanup/optimization | Status: new
Component: contrib.admin | Version: dev
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 1
--------------------------------------+------------------------------------
Comment (by Marijke Luttekes):

I am still unsure of what the UI would be for fieldsets (collapsible or
otherwise) in TabularInlines.

A tabular inline is a table; tables are naturally single-use elements: a
table contains cells, an optional caption, and nothing more fancy.
They are also very consistent in that they are just as annoying to
customize, style, and make responsive as they were many years ago.

There was a suggestion to make the columns collapsible instead. This is
not something that can be achieved without using custom JavaScript.
Per the specs, the HTML collapsible details element is not allowed within
a table, nor did it work when one of our Discord members tried it in a
proof of concept.

Per the above, I am also in favor of option 2.
--
Ticket URL: <https://code.djangoproject.com/ticket/35464#comment:3>

Django

unread,
Jun 20, 2024, 6:14:42 PMJun 20
to django-...@googlegroups.com
#35464: Fieldsets defined for TabularInlines are ignored
-------------------------------------+-------------------------------------
Reporter: Natalia Bidart | Owner: Maryam
Type: | Yusuf
Cleanup/optimization | Status: assigned
Component: contrib.admin | Version: dev
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 1
-------------------------------------+-------------------------------------
Changes (by Maryam Yusuf):

* owner: nobody => Maryam Yusuf
* status: new => assigned

--
Ticket URL: <https://code.djangoproject.com/ticket/35464#comment:4>

Django

unread,
Jun 24, 2024, 10:38:28 AM (11 days ago) Jun 24
to django-...@googlegroups.com
#35464: Fieldsets defined for TabularInlines are ignored
-------------------------------------+-------------------------------------
Reporter: Natalia Bidart | Owner: Maryam
Type: | Yusuf
Cleanup/optimization | Status: assigned
Component: contrib.admin | Version: dev
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 1
-------------------------------------+-------------------------------------
Changes (by Sarah Boyce):

* has_patch: 0 => 1

--
Ticket URL: <https://code.djangoproject.com/ticket/35464#comment:5>

Django

unread,
Jun 26, 2024, 5:31:38 PM (9 days ago) Jun 26
to django-...@googlegroups.com
#35464: Fieldsets defined for TabularInlines are ignored
-------------------------------------+-------------------------------------
Reporter: Natalia Bidart | Owner: Maryam
Type: | Yusuf
Cleanup/optimization | Status: assigned
Component: contrib.admin | Version: dev
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 1
-------------------------------------+-------------------------------------
Changes (by Ryan Cheley):

* cc: Ryan Cheley (added)

--
Ticket URL: <https://code.djangoproject.com/ticket/35464#comment:6>

Django

unread,
Jul 3, 2024, 11:26:52 AM (2 days ago) Jul 3
to django-...@googlegroups.com
#35464: Fieldsets defined for TabularInlines are ignored
-------------------------------------+-------------------------------------
Reporter: Natalia Bidart | Owner: Maryam
Type: | Yusuf
Cleanup/optimization | Status: assigned
Component: contrib.admin | Version: dev
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1
Easy pickings: 0 | UI/UX: 1
-------------------------------------+-------------------------------------
Changes (by Sarah Boyce):

* needs_better_patch: 0 => 1

--
Ticket URL: <https://code.djangoproject.com/ticket/35464#comment:7>

Django

unread,
Jul 4, 2024, 5:10:02 AM (yesterday) Jul 4
to django-...@googlegroups.com
#35464: Fieldsets defined for TabularInlines are ignored
-------------------------------------+-------------------------------------
Reporter: Natalia Bidart | Owner: Maryam
Type: | Yusuf
Cleanup/optimization | Status: assigned
Component: contrib.admin | Version: dev
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1
Easy pickings: 0 | UI/UX: 1
-------------------------------------+-------------------------------------
Comment (by Marijke Luttekes):

The following comment is only for future reference; no action is required:

Somewhat related to this ticket: Lullabot created a Drupal (a PHP web
framework) plugin for responsive HTML tables and described their entire
thought process.

The article does not discuss collapsible fieldsets, but I want to park it
here since it relates to Natalia's research following the creation of this
ticket:
[https://www.lullabot.com/articles/responsive-html-tables-presenting-data-
accessible-way Responsive HTML Tables: Presenting Data in an Accessible
Way]

''Note: Take the bit where they mandate table `<caption>` with a grain of
salt; I know screen reader users who don't like those because it gets in
the way of their screen reader reading the table headings.''
--
Ticket URL: <https://code.djangoproject.com/ticket/35464#comment:8>
Reply all
Reply to author
Forward
0 new messages