Skip to content


Subversion checkout URL

You can clone with
Download ZIP


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

wants to merge 5 commits into from

3 participants


This is consistent with the other ModelAdmin methods. Please refer to for further information.


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 :


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


Merged in c2e19e2.

@aaugustin aaugustin closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jul 12, 2012
  1. @sjaensch

    get_inline_instances() should follow the API in the module and accept…

    sjaensch committed
    … and pass along an instance parameter
Commits on Jul 13, 2012
  1. @sjaensch
Commits on Aug 3, 2012
  1. @sjaensch

    Merge pull request #1 from domguard/inline_instance_obj_param

    sjaensch committed
    Updated docs/ref/contrib/admin/index.txt : add get_inline_instances method
  2. @sjaensch
This page is out of date. Refresh to see the latest.
12 django/contrib/admin/
@@ -343,14 +343,14 @@ def __init__(self, model, admin_site):
self.admin_site = admin_site
super(ModelAdmin, self).__init__()
- def get_inline_instances(self, request):
+ def get_inline_instances(self, request, obj=None):
inline_instances = []
for inline_class in self.inlines:
inline = inline_class(self.model, self.admin_site)
if request:
if not (inline.has_add_permission(request) or
- inline.has_change_permission(request) or
- inline.has_delete_permission(request)):
+ inline.has_change_permission(request, obj) or
+ inline.has_delete_permission(request, obj)):
if not inline.has_add_permission(request):
inline.max_num = 0
@@ -503,7 +503,7 @@ def get_changelist_formset(self, request, **kwargs):
fields=self.list_editable, **defaults)
def get_formsets(self, request, obj=None):
- for inline in self.get_inline_instances(request):
+ for inline in self.get_inline_instances(request, obj):
yield inline.get_formset(request, obj)
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):
ModelForm = self.get_form(request)
formsets = []
- inline_instances = self.get_inline_instances(request)
+ inline_instances = self.get_inline_instances(request, None)
if request.method == 'POST':
form = ModelForm(request.POST, request.FILES)
if form.is_valid():
@@ -1029,7 +1029,7 @@ def change_view(self, request, object_id, form_url='', extra_context=None):
ModelForm = self.get_form(request, obj)
formsets = []
- inline_instances = self.get_inline_instances(request)
+ inline_instances = self.get_inline_instances(request, obj)
if request.method == 'POST':
form = ModelForm(request.POST, request.FILES, instance=obj)
if form.is_valid():
10 docs/ref/contrib/admin/index.txt
@@ -1047,6 +1047,16 @@ templates used by the :class:`ModelAdmin` views:
changelist that will be linked to the change view, as described in the
:attr:`ModelAdmin.list_display_links` section.
+.. method:: ModelAdmin.get_inline_instances(self, request, obj=None)
+ .. versionadded:: 1.5
+ The ``get_inline_instances`` method is given the ``HttpRequest`` and the
+ ``obj`` being edited (or ``None`` on an add form) and is expected to return
+ a ``list`` or ``tuple`` of :class:`~django.contrib.admin.InlineModelAdmin`
+ objects, as described below in the :class:`~django.contrib.admin.InlineModelAdmin`
+ section.
.. method:: ModelAdmin.get_urls(self)
The ``get_urls`` method on a ``ModelAdmin`` returns the URLs to be used for
Something went wrong with that request. Please try again.