Opened 10 months ago

Last modified 10 months ago

#27755 new New feature

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

Reported by: WeizhongTu Owned by: nobody
Component: contrib.admin Version: master
Severity: Normal Keywords: django, admin, inlines
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: yes
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 (3)

comment:1 Changed 10 months 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 10 months 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 10 months ago by Tim Graham (previous) (diff)

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

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