{{{
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!
--
Ticket URL: <https://code.djangoproject.com/ticket/30626>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* Attachment "nac35ntlfg831.jpg" added.
Validation error
* status: new => closed
* version: 2.2 => master
* resolution: => invalid
Comment:
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
[https://docs.djangoproject.com/en/2.2/ref/models/fields/#blank` blank
documentation]) and `default` will not be used because value (empty) is
provided (see
[https://docs.djangoproject.com/en/2.2/ref/models/fields/#default default
documentation]). In the same time you have `NOT NULL` constraint in a
database.
Closing per TicketClosingReasons/UseSupportChannels.
--
Ticket URL: <https://code.djangoproject.com/ticket/30626#comment:1>
--
Ticket URL: <https://code.djangoproject.com/ticket/30626#comment:2>