Adding/Removing admin Inlines on the fly
|Reported by:||sheep2||Owned by:||nobody|
|Cc:||Triage Stage:||Design decision needed|
|Has patch:||yes||Needs documentation:||yes|
|Needs tests:||yes||Patch needs improvement:||yes|
Inlines are very useful for creating/updating related objects at the same time. However, sometimes you only want to create/update one of the objects instead of both. For example, when creating a User you may not want to add the associated content in a related profile model, but want to do so later.
The current implementation defines and instantiates the inlines when a admin.ModelAdmin class is instantiated, but does not allow addition/removal of more inlines anywhere(or anytime) else.
I propose two functions register_inline_instance() and unregister_inline_instance() that allow inlines to be added and removed from a model on the fly.
class UserAdmin(admin.ModelAdmin): inlines = [StudentInline,] ... def add_view(self, request, form_url='', extra_context=None): self.unregister_inline_instance(StudentInline) return super(UserAdmin, self).add_view(request, form_url, extra_context) def change_view(self, request, form_url='', extra_context=None): self.register_inline_instance(StudentInline) return super(UserAdmin, self).change_view(request, form_url, extra_context) ...
Change History (7)
Changed 4 years ago by sheep2
comment:1 follow-up: ↓ 2 Changed 4 years ago by julien
- Needs documentation set
- Needs tests set
- Patch needs improvement set
- Triage Stage changed from Unreviewed to Design decision needed