Admin inlines incorrectly report "this field is required" if inline model has field with default value
|Reported by:||Russell Keith-Magee||Owned by:||Brian Rosner|
|Has patch:||yes||Needs documentation:||no|
|Needs tests:||no||Patch needs improvement:||no|
Consider the following model:
class Person(models.Model): name = models.CharField(max_length=128) class Membership(models.Model): person = models.ForeignKey(Person) date_joined = models.DateTimeField(default=datetime.now)
with the following admin definition:
class MembershipInline(admin.TabularInline): model = Membership extra = 3 class PersonAdmin(admin.ModelAdmin): inlines = (MembershipInline,) admin.site.register(Person, PersonAdmin)
If you try to add or edit an instance of Person in the admin, you won't be able to save unless you fill in _all_ the extra lines in the inline.
This appears to be because the default value that is used to populate the inline form is confused with legitimate user-entered content. As a result, all the empty extra rows appear to have been partially filled out, so the validator raises an error for the 'missing' fields.
If you remove the default value from the date_joined field, the problem goes away.
Change History (26)
comment:6 Changed 8 years ago by
|Owner:||changed from nobody to Manuel Saelices|
|Status:||new → assigned|
comment:16 Changed 8 years ago by
|Owner:||changed from Manuel Saelices to Brian Rosner|
|Status:||reopened → new|
comment:20 Changed 14 months ago by