Opened 9 years ago
Closed 7 years 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: | dev |
| 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)
follow-up: 2 comment:1 by , 9 years ago
comment:2 by , 9 years ago
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 by , 9 years ago
| 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.
comment:4 by , 7 years ago
| Owner: | changed from to |
|---|---|
| Status: | new → assigned |
comment:5 by , 7 years ago
| Owner: | changed from to |
|---|---|
| Patch needs improvement: | unset |
comment:6 by , 7 years ago
| Triage Stage: | Accepted → Ready for checkin |
|---|
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.