Opened 2 years ago

Closed 5 weeks ago

#27755 closed New feature (fixed)

add ModelAdmin.get_inlines() hook to allow set inlines based on the request or model instance.

Reported by: WeizhongTu Owned by: Hasan Ramezani
Component: contrib.admin Version: master
Severity: Normal Keywords: django, admin, inlines
Cc: Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

add ModelAdmin.get_inlines() hook to allow set inlines based on the request or model instance.
Currently, We can override the method get_inline_instances to do such a thing, but a for loop should be copied to my code. So I wished add a hook get_inlines(request, obj=None)

Change History (7)

comment:1 Changed 2 years ago by Tim Graham

Are you going to offer a patch to show exactly what you have in mind? I'm not immediately convinced that another hook is needed since the cost of duplicating a for loop is not that great.

comment:2 in reply to:  1 Changed 2 years ago by WeizhongTu

If I want to realize a dynamic inlines based on the request or model instance. I need to override get_inline_instances to do it.
What I want to do is just set self.inlines to dynamic values according to different person or object. not inline instances, so I advise to add a new hook get_inlines(request, obj=None) to finish such a thing.

I've created a new pull request here: ​https://github.com/django/django/pull/7920.

Last edited 2 years ago by Tim Graham (previous) (diff)

comment:3 Changed 2 years ago by Tim Graham

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

I guess it's useful. The patch needs some improvement (tests, some doc fixes such as release notes) as per the PatchReviewChecklist.

comment:4 Changed 6 months ago by Hidde Bultsma

Owner: changed from nobody to Hidde Bultsma
Status: newassigned

comment:5 Changed 2 months ago by Hasan Ramezani

Owner: changed from Hidde Bultsma to Hasan Ramezani
Patch needs improvement: unset
Last edited 2 months ago by Tim Graham (previous) (diff)

comment:6 Changed 5 weeks ago by felixxm

Triage Stage: AcceptedReady for checkin

comment:7 Changed 5 weeks ago by Mariusz Felisiak <felisiak.mariusz@…>

Resolution: fixed
Status: assignedclosed

In 917fd9d0:

Fixed #27755 -- Added ModelAdmin.get_inlines() hook.

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