#30626 closed Bug (invalid)
InlineModelAdmin fails of an empty form when DecimalField has default and blank=True.
| Reported by: | Dmitry Chaplinsky | Owned by: | nobody |
|---|---|---|---|
| Component: | contrib.admin | Version: | dev |
| 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 following code for the model:
class PayrollItem(models.Model):
payroll = models.ForeignKey(
"Payroll",
verbose_name="Payroll",
on_delete=models.CASCADE,
related_name="items",
)
contract = models.ForeignKey(
"Contract",
verbose_name="Contract",
on_delete=models.CASCADE,
related_name="payments",
)
hours = models.DecimalField("Hours", decimal_places=2, default="0.00", max_digits=7, blank=True)
current_rate = models.DecimalField(
"Hourly rate", decimal_places=2, default="0.00", max_digits=7, blank=True
)
which is then added as an InlineModelAdmin:
class PayrollItemInline(admin.TabularInline):
extra = 1
model = PayrollItem
when I hit save parent object, Django raises validation error for foreign key of an empty inline form like in attached file
If I exclude "hours", "current_rate" everything works as expected!
Attachments (1)
Change History (3)
by , 6 years ago
| Attachment: | nac35ntlfg831.jpg added |
|---|
comment:1 by , 6 years ago
| Resolution: | → invalid |
|---|---|
| Status: | new → closed |
| Summary: | InlineModelAdmin fails validation of an empty form when there are ForeignKey and DecimalField with default="0.00" → InlineModelAdmin fails validation of an empty form when there are ForeignKey and DecimalField with default="0.00". |
| Version: | 2.2 → master |
Thanks for this report, however your models configuration allows for such behavior. If a field has blank=True form validation will allow entry of an empty value (see blank documentation) and default will not be used because value (empty) is provided (see default documentation). In the same time you have NOT NULL constraint in a database.
Closing per TicketClosingReasons/UseSupportChannels.
comment:2 by , 6 years ago
| Summary: | InlineModelAdmin fails validation of an empty form when there are ForeignKey and DecimalField with default="0.00". → InlineModelAdmin fails of an empty form when DecimalField has default and blank=True. |
|---|
Validation error