Code

Opened 8 months ago

Closed 3 months ago

Last modified 3 months ago

#21353 closed Bug (fixed)

'description' key in InlineModelAdmin fieldsets is ignored

Reported by: nofinator 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.

Attachments (0)

Change History (11)

comment:1 Changed 8 months ago by nofinator

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

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 follow-up: Changed 8 months ago by timo

  • Has patch set
  • Needs tests set
  • Patch needs improvement set
  • Triage Stage changed from Unreviewed to Accepted

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

comment:3 Changed 8 months ago by chexov34@…

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

comment:4 Changed 8 months ago by nofinator

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 8 months ago by nofinator

  • Resolution set to fixed
  • Status changed from new to closed

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 8 months ago by nofinator

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

comment:7 Changed 8 months ago by nofinator

  • Needs tests unset
  • Resolution fixed deleted
  • Status changed from closed to new

I think I set the resolution to fixed prematurely.

comment:8 Changed 8 months ago by timo

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 months ago by Tim Graham <timograham@…>

  • Resolution set to fixed
  • Status changed from new to closed

In d5031ecf881eaefe7ada1c35228b35a1852dd343:

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

Thanks nofinator for the report.

comment:10 Changed 3 months 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 months 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

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.