﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
27991	Add 'obj' kwarg to InlineModelAdmin.has_add_permission()	Olivier Dalang	Vladimir Ivanov	"Hi !

{{{InlineModelAdmin}}} has the following methods :

{{{
def has_add_permission(self, request):
    ...
def has_change_permission(self, request, obj=None):
    ...
def has_delete_permission(self, request, obj=None):
    ...
}}}

In those methods, the {{{obj}}} parameter represents the parent instance. So, by overriding {{{ModelInline.has_change_permission}}} you can have some specific logic to define whether an user can change inlines objects depending on the parent object.

The thing is that the {{{has_add_permission}}} misses this argument. It probably came from a confusion between the parent instance (the {{{obj}}} argument) and the child instance (not accessible).

Still, exactly as it makes sense overriding {{{ModelInline.has_change_permission}}}, we may need to have some specific logic to define whether an user can add inlines objects depending on the parent object.

I suggest we add the {{{obj}}} argument to {{{ModelInline.has_add_permission}}}, and make it more clear (both in the doc and as comments in the code) that {{{obj}}} refers to the parent instance, and not the inline instance.

It would be awesome if those methods also took the inline instance as a parameter (eg. {{{def has_change_permission(self, request, obj=None, childObj=None):}}} to keep it backwards compatible ) but that would probably be for another ticket.

Thanks !

Olivier
"	Cleanup/optimization	closed	contrib.admin	1.10	Normal	fixed		Manel Clos	Ready for checkin	1	0	0	0	0	0
