#29676: has_add_permission() returning False in TabularInline form raises
exception
in contrib.admin
-------------------------------------+-------------------------------------
Reporter: Ivan | Owner: nobody
Belokobylskiy |
Type: Bug | Status: new
Component: | Version: 2.1
contrib.admin | Keywords: admin
Severity: Normal | has_add_permission
Triage Stage: | Has patch: 0
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------+-------------------------------------
I have TabularInline form does not have add permission and not all fields
are read-only.
Its model has a FK to parent model without any restrictions.
When I try to create a new parent model via contrib.admin form KeyError
exception raised.
This example application fails on Django 2.1, Python 3.6 when I try to
visit
http://localhost:8000/admin/app/parentmodel/add/
It raises {{{KeyError: 'editable_field'}}}
=== models.py
{{{
from django.db import models
class ParentModel(models.Model):
name = models.CharField(max_length=255)
class InlineModel(models.Model):
editable_field = models.CharField(max_length=255)
readonly_field = models.CharField(max_length=255)
parent = models.ForeignKey(ParentModel, on_delete=models.CASCADE)
}}}
=== admin.py
{{{
from django.contrib import admin
from .models import InlineModel, ParentModel
class InlineModelInline(admin.TabularInline):
model = InlineModel
fields = (
'editable_field',
'readonly_field',
)
readonly_fields = (
'readonly_field',
)
def has_add_permission(self, request, obj):
return False
@admin.register(ParentModel)
class ParentModelAdmin(admin.ModelAdmin):
fields = ['name']
inlines = [InlineModelInline]
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/29676>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/049.e23472aa3be94c31483cf573ed72b605%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.