Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Ticket #18619: get_inline_instances() should accept an instance parameter #202

Closed
wants to merge 5 commits into from

3 participants

Stephan Jaensch Dominique Guardiola Aymeric Augustin
Stephan Jaensch

This is consistent with the other ModelAdmin methods. Please refer to https://code.djangoproject.com/ticket/18619 for further information.

Dominique Guardiola

Yes, taking permissions in account was missing in my patch
You just miss another mention of the paramter at line 934, see my comment here : https://code.djangoproject.com/ticket/17856#comment:10

Stephan Jaensch

Thanks, setting it explicitly is indeed better than relying on the default value.

Aymeric Augustin
Owner

Merged in c2e19e2.

Aymeric Augustin aaugustin closed this October 20, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Showing 5 unique commits by 3 authors.

Jul 12, 2012
Stephan Jaensch get_inline_instances() should follow the API in the module and accept…
… and pass along an instance parameter
6a36294
Jul 13, 2012
Stephan Jaensch explicitly specify the obj parameter 4b97f44
Aug 03, 2012
Updated docs/ref/contrib/admin/index.txt to add get_inline_instances …
…method
db3dc04
Stephan Jaensch Merge pull request #1 from domguard/inline_instance_obj_param
Updated docs/ref/contrib/admin/index.txt : add get_inline_instances method
1c1d245
Stephan Jaensch Minor text and formatting change b13d4ed
This page is out of date. Refresh to see the latest.
12  django/contrib/admin/options.py
@@ -343,14 +343,14 @@ def __init__(self, model, admin_site):
343 343
         self.admin_site = admin_site
344 344
         super(ModelAdmin, self).__init__()
345 345
 
346  
-    def get_inline_instances(self, request):
  346
+    def get_inline_instances(self, request, obj=None):
347 347
         inline_instances = []
348 348
         for inline_class in self.inlines:
349 349
             inline = inline_class(self.model, self.admin_site)
350 350
             if request:
351 351
                 if not (inline.has_add_permission(request) or
352  
-                        inline.has_change_permission(request) or
353  
-                        inline.has_delete_permission(request)):
  352
+                        inline.has_change_permission(request, obj) or
  353
+                        inline.has_delete_permission(request, obj)):
354 354
                     continue
355 355
                 if not inline.has_add_permission(request):
356 356
                     inline.max_num = 0
@@ -503,7 +503,7 @@ def get_changelist_formset(self, request, **kwargs):
503 503
             fields=self.list_editable, **defaults)
504 504
 
505 505
     def get_formsets(self, request, obj=None):
506  
-        for inline in self.get_inline_instances(request):
  506
+        for inline in self.get_inline_instances(request, obj):
507 507
             yield inline.get_formset(request, obj)
508 508
 
509 509
     def get_paginator(self, request, queryset, per_page, orphans=0, allow_empty_first_page=True):
@@ -931,7 +931,7 @@ def add_view(self, request, form_url='', extra_context=None):
931 931
 
932 932
         ModelForm = self.get_form(request)
933 933
         formsets = []
934  
-        inline_instances = self.get_inline_instances(request)
  934
+        inline_instances = self.get_inline_instances(request, None)
935 935
         if request.method == 'POST':
936 936
             form = ModelForm(request.POST, request.FILES)
937 937
             if form.is_valid():
@@ -1029,7 +1029,7 @@ def change_view(self, request, object_id, form_url='', extra_context=None):
1029 1029
 
1030 1030
         ModelForm = self.get_form(request, obj)
1031 1031
         formsets = []
1032  
-        inline_instances = self.get_inline_instances(request)
  1032
+        inline_instances = self.get_inline_instances(request, obj)
1033 1033
         if request.method == 'POST':
1034 1034
             form = ModelForm(request.POST, request.FILES, instance=obj)
1035 1035
             if form.is_valid():
10  docs/ref/contrib/admin/index.txt
@@ -1047,6 +1047,16 @@ templates used by the :class:`ModelAdmin` views:
1047 1047
     changelist that will be linked to the change view, as described in the
1048 1048
     :attr:`ModelAdmin.list_display_links` section.
1049 1049
 
  1050
+.. method:: ModelAdmin.get_inline_instances(self, request, obj=None)
  1051
+
  1052
+    .. versionadded:: 1.5
  1053
+
  1054
+    The ``get_inline_instances`` method is given the ``HttpRequest`` and the
  1055
+    ``obj`` being edited (or ``None`` on an add form) and is expected to return
  1056
+    a ``list`` or ``tuple`` of :class:`~django.contrib.admin.InlineModelAdmin`
  1057
+    objects, as described below in the :class:`~django.contrib.admin.InlineModelAdmin`
  1058
+    section.
  1059
+
1050 1060
 .. method:: ModelAdmin.get_urls(self)
1051 1061
 
1052 1062
     The ``get_urls`` method on a ``ModelAdmin`` returns the URLs to be used for
Commit_comment_tip

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.