Opened 7 years ago
Closed 7 years ago
#29355 closed Bug (needsinfo)
ArrayField in admin inline form try to save null instead default value
Reported by: | Irina Silvestrova | Owned by: | nobody |
---|---|---|---|
Component: | Uncategorized | Version: | |
Severity: | Normal | Keywords: | |
Cc: | Triage Stage: | Unreviewed | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
I have buit-in User
class and the Employee
class, one-to-one with User
. It has an ArrayField
inside:
role = ArrayField( models.IntegerField(choices=UserRole.choices(), blank=True, null=True), verbose_name='User Roles', blank=True, default=list )
It is not nullable, but has default value.
In admin, I have the class EmployeeInline
:
class EmployeeInline(admin.StackedInline): model = models.Employee can_delete = False verbose_name_plural = 'employee'
And use it in the UserAdmin
class in the following way:
@admin.register(models.User) class UserAdmin(DefaultUserAdmin): def change_view(self, request, object_id, form_url='', extra_context=None): self.inlines = [EmployeeInline] return super(UserAdmin, self).change_view( request, object_id, form_url, extra_context )
I see role field correct on the admin page, but if I try to save the model without selected role, I have an error:
IntegrityError at /admin/auth/user/232/change/ null value in column "role" violates not-null constraint DETAIL: Failing row contains (232, , 232, , , , 31, t, f, null, null).
Change History (2)
comment:1 by , 7 years ago
comment:2 by , 7 years ago
Resolution: | → needsinfo |
---|---|
Status: | new → closed |
I tried to reproduce this and couldn't do so. The details are somewhat sparse, perhaps you might provide a sample project.
Note:
See TracTickets
for help on using tickets.
What version of Django are you using? Does the problem happen in non-inline forms? I can't reproduce the issue there and I didn't try the complete steps you offered.