Opened 3 years ago

Closed 3 years ago

Last modified 3 years ago

#21353 closed Bug (fixed)

'description' key in InlineModelAdmin fieldsets is ignored

Reported by: Greg Owned by: nobody
Component: contrib.admin Version: master
Severity: Normal Keywords:
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: yes
Easy pickings: no UI/UX: no

Description

The InlineModelAdmin supports fieldsets, just like ModelAdmin objects. However, if you add a 'description' key, it does not appear on the rendered form.

For example:

class BookInline(admin.TabularInline):
    model = Book
    fieldsets = (
        (None, {
            'description': 'These are the related books.',
            'fields': ('name', 'date'),
        }),
    )

I would expect to see 'These are the related books.' in the tabular inline section for Books, but I don't.

(I suspect other fieldset keys are ignored in inlines, too. I haven't tried those.)

I am will share a branch with a fix for this on GitHub soon.

Change History (11)

comment:1 Changed 3 years ago by Greg

Here is a link to a branch with a fix in my repo: https://github.com/nofeet/django/tree/ticket_21353

It looks for and uses the description for only the first fieldset in the inline admin form. I'm not exactly sure how the inline fieldsets and forms work, so this is the cleanest fix I came across after several attempts. Perhaps someone with more knowledge can come up with a better solution.

comment:2 Changed 3 years ago by Tim Graham

Has patch: set
Needs tests: set
Patch needs improvement: set
Triage Stage: UnreviewedAccepted

This should be fixed on stacked.html as well. It also needs tests in order to be merged.

comment:3 Changed 3 years ago by chexov34@…

Hello nofinator.
Can I help you for create tests ? :)
My mail: chexov34@…

comment:4 Changed 3 years ago by Greg

Thanks, chexov34, but since this is my first dev work for the Django code base, I'd like to give it a try. I saw that there are already some test InlineAdmin models with fieldsets already, so I hope to write the tests within the next few days.

comment:5 in reply to:  2 Changed 3 years ago by Greg

Resolution: fixed
Status: newclosed

Replying to timo:

This should be fixed on stacked.html as well.

I tried out StackedInlines and they work already for fieldsets because stacked.html includes fieldset.html.

It also needs tests in order to be merged.

Ah, of course. I just pushed a test for this on my branch.

comment:6 Changed 3 years ago by Greg

I also created a pull request if you think it's ready: https://github.com/django/django/pull/1882

comment:7 Changed 3 years ago by Greg

Needs tests: unset
Resolution: fixed
Status: closednew

I think I set the resolution to fixed prematurely.

comment:8 Changed 3 years ago by Tim Graham

As I noticed on the pull request, fieldset.name isn't rendered either, maybe this was intentionally omitted in the tabular inline. Just stacking up the descriptions where they don't really correspond to the fields doesn't seem very elegant. It may be best just to document that description doesn't apply when using TabularInlines.

comment:9 Changed 3 years ago by Tim Graham <timograham@…>

Resolution: fixed
Status: newclosed

In d5031ecf881eaefe7ada1c35228b35a1852dd343:

Fixed #21353 -- Noted that description is ignored for TabularInlines.

Thanks nofinator for the report.

comment:10 Changed 3 years ago by Tim Graham <timograham@…>

In ae78227de3740cce7e2b460b2845f19443c4d090:

[1.7.x] Fixed #21353 -- Noted that description is ignored for TabularInlines.

Thanks nofinator for the report.

Backport of d5031ecf88 from master

comment:11 Changed 3 years ago by Tim Graham <timograham@…>

In de95867284ddf84bb4ca5e5946bae96d5d23babf:

[1.6.x] Fixed #21353 -- Noted that description is ignored for TabularInlines.

Thanks nofinator for the report.

Backport of d5031ecf88 from master

Note: See TracTickets for help on using tickets.
Back to Top