Skip to content

Commit

Permalink
Added a root_obj field to the NestedInline class
Browse files Browse the repository at this point in the history
  • Loading branch information
ralkan authored and Resul Alkan committed Mar 28, 2018
1 parent cfa5a07 commit b2afb74
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions nested_inline/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,7 @@ def change_view(self, request, object_id, form_url='', extra_context=None):

inline_admin_formsets = []
for inline, formset in zip(inline_instances, formsets):
inline.root_obj = obj
fieldsets = list(inline.get_fieldsets(request, obj))
readonly = list(inline.get_readonly_fields(request, obj))
prepopulated = dict(inline.get_prepopulated_fields(request, obj))
Expand Down Expand Up @@ -350,6 +351,7 @@ def change_view(self, request, object_id, form_url='', extra_context=None):


class NestedInline(InlineModelAdmin):
root_obj = None
inlines = []
new_objects = []

Expand All @@ -367,6 +369,7 @@ def get_inline_instances(self, request, obj=None):
inline_instances = []
for inline_class in self.inlines:
inline = inline_class(self.model, self.admin_site)
inline.root_obj = self.root_obj
if request:
if not (inline.has_add_permission(request) or
inline.has_change_permission(request, obj) or
Expand Down

0 comments on commit b2afb74

Please sign in to comment.