Code

Ticket #17856: adding_obj_parameter_to_get_inline_instances.diff

File adding_obj_parameter_to_get_inline_instances.diff, 1.4 KB (added by ybon, 2 years ago)

Adding "obj" parameter to get_inline_instances method in contrib.admin

Line 
1diff --git a/django/contrib/admin/options.py b/django/contrib/admin/options.py
2index f5f6256..e6749ba 100644
3--- a/django/contrib/admin/options.py
4+++ b/django/contrib/admin/options.py
5@@ -345,7 +345,7 @@ class ModelAdmin(BaseModelAdmin):
6         self.admin_site = admin_site
7         super(ModelAdmin, self).__init__()
8 
9-    def get_inline_instances(self, request):
10+    def get_inline_instances(self, request, obj=None):
11         inline_instances = []
12         for inline_class in self.inlines:
13             inline = inline_class(self.model, self.admin_site)
14@@ -505,7 +505,7 @@ class ModelAdmin(BaseModelAdmin):
15             fields=self.list_editable, **defaults)
16 
17     def get_formsets(self, request, obj=None):
18-        for inline in self.get_inline_instances(request):
19+        for inline in self.get_inline_instances(request, obj):
20             yield inline.get_formset(request, obj)
21 
22     def get_paginator(self, request, queryset, per_page, orphans=0, allow_empty_first_page=
23@@ -1031,7 +1031,7 @@ class ModelAdmin(BaseModelAdmin):
24 
25         ModelForm = self.get_form(request, obj)
26         formsets = []
27-        inline_instances = self.get_inline_instances(request)
28+        inline_instances = self.get_inline_instances(request, obj)
29         if request.method == 'POST':
30             form = ModelForm(request.POST, request.FILES, instance=obj)
31             if form.is_valid():
32