Opened 15 months ago
Last modified 15 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 follow-up: 2 Changed 15 months ago by
comment:2 Changed 15 months ago by
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.
comment:3 Changed 15 months ago by
Has patch: | set |
---|---|
Patch needs improvement: | set |
Triage Stage: | Unreviewed → Accepted |
I guess it's useful. The patch needs some improvement (tests, some doc fixes such as release notes) as per the PatchReviewChecklist.
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.