#6762 closed (duplicate)
TabularInline in Admin breaks when fields have default values
| Reported by: | ingenieroariel | Owned by: | nobody |
|---|---|---|---|
| Component: | contrib.admin | Version: | newforms-admin |
| Severity: | Keywords: | inline, default, save, newforms-admin | |
| Cc: | Triage Stage: | Unreviewed | |
| Has patch: | no | Needs documentation: | no |
| Needs tests: | no | Patch needs improvement: | no |
| Easy pickings: | UI/UX: |
Description
In the following code, everytime the save button is hit in the parent change_form it complains about empty inline model.
I guess it is because default values are assigned to some fields and it tries to save the partially empty objects.
Here is a simple example that works ok, without the default
from django.db import models
from django.contrib import admin
# Create your models here.
class Parent(models.Model):
name=models.CharField(max_length=20)
CHOICES = (
('choice', 'choice'),
('choice1', 'choice1'),
)
class Son(models.Model):
name=models.CharField(max_length=20)
parent=models.ForeignKey(Parent)
choice=models.CharField(max_length=20, choices=CHOICES, default='choice')
class SonModelInline(admin.TabularInline):
model = Son
extra = 1
class ParentOptions(admin.ModelAdmin):
inlines = [SonModelInline]
admin.site.register(Son)
admin.site.register(Parent, ParentOptions)
Note:
See TracTickets
for help on using tickets.
Dup of #5878, I believe.