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 29701 has_add_permission in admin.TabularInline gives KeyError exception Harm Verhagen nobody "I noticed that using {{{has_add_permission()}}} on a {{{admin.TabularInline}}} fails if it returns False. If it returns True, all works as expected. See the simple example below. === steps to reproduce models.py {{{ class ModelA(models.Model): name = models.CharField(max_length=2) bs = models.ManyToManyField(""ModelB"", through=""Through"") def __str__(self): return ""%s"" % self.name class ModelB(models.Model): name = models.CharField(max_length=2) def __str__(self): return ""%s"" % self.name class Through(models.Model): a = models.ForeignKey(ModelA, on_delete=models.CASCADE) b = models.ForeignKey(ModelB, on_delete=models.CASCADE) def __str__(self): return ""%s-%s"" % (self.a, self.b) }}} admin.py {{{ class ThroughInline(admin.TabularInline): model = Through def has_add_permission(self, request, obj): # setting this to False results in an error return False class ModelAAdmin(admin.ModelAdmin): inlines = (ThroughInline, ) class ModelBAdmin(admin.ModelAdmin): inlines = (ThroughInline, ) class ThroughAdmin(admin.ModelAdmin): pass }}} Then create your objects. {{{ >>> from .models import ModelA, ModelB, Through >>> a = ModelA.objects.create(name='a') >>> b= ModelB.objects.create(name='b') >>> t = Through.objects.create(a=a, b=b) }}} Fire up a runserver and visit the admin api: http://localhost:8000/admin//modela/1/change/ === result A server 500 {{{ KeyError at /admin//modela/1/change/ Request Method: GET Request URL: http://localhost:8000/admin//modela/1/change/ Django Version: 2.1 Exception Type: KeyError Exception Value: 'b' Template error: In template ...contrib/admin/templates/admin/edit_inline/tabular.html, error at line 13 b 3 : data-inline-type=""tabular"" 4 : data-inline-formset=""{{ inline_admin_formset.inline_formset_data }}""> 5 :
6 : {{ inline_admin_formset.formset.management_form }} 7 :
8 :

{{ inline_admin_formset.opts.verbose_name_plural|capfirst }}

9 : {{ inline_admin_formset.formset.non_form_errors }} 10 : 11 : 12 : 13 : {% for field in inline_admin_formset.fields %} 14 : {% if not field.widget.is_hidden %} 15 : {{ field.label|capfirst }} 16 : {% if field.help_text %} {% endif %} 17 : 18 : {% endif %} 19 : {% endfor %} 20 : {% if inline_admin_formset.formset.can_delete %}{% endif %} 21 : 22 : 23 : Traceback: File ""/venv3/lib/python3.5/site-packages/django/core/handlers/exception.py"" in inner 34. response = get_response(request) File ""/venv3/lib/python3.5/site-packages/django/core/handlers/base.py"" in _get_response 156. response = self.process_exception_by_middleware(e, request) File ""/venv3/lib/python3.5/site-packages/django/core/handlers/base.py"" in _get_response 154. response = response.render() File ""/venv3/lib/python3.5/site-packages/django/template/response.py"" in render 106. self.content = self.rendered_content File ""/venv3/lib/python3.5/site-packages/django/template/response.py"" in rendered_content 83. content = template.render(context, self._request) }}} === expected result The inlines are displayed without the option to create new Through instances. === version {{{Django==2.1}}}" Bug closed contrib.admin 2.1 Normal duplicate Unreviewed 0 0 0 0 0 0
{% trans ""Delete?"" %}