Opened 8 years ago
Closed 8 years ago
#27955 closed Bug (invalid)
JSONField.default not applied in admin
Reported by: | Jannis Vajen | Owned by: | nobody |
---|---|---|---|
Component: | contrib.admin | Version: | 1.10 |
Severity: | Normal | Keywords: | JSONField, admin |
Cc: | Triage Stage: | Unreviewed | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description (last modified by )
Consider a model like this:
class Example(models.Model): json = JSONField( default=list, blank=True )
Creating an object programmatically works and applies the default value just fine. Saving an object with an empty value for the JSONField
triggers an IntegrityError
because Django tries to save an object with null
instead of the default.
I'm not sure whether this ticket is a duplicate of #27697 but I think this issue with the ignored default may have a different origin.
Change History (2)
comment:1 by , 8 years ago
Description: | modified (diff) |
---|
comment:2 by , 8 years ago
Description: | modified (diff) |
---|---|
Resolution: | → invalid |
Status: | new → closed |
Note:
See TracTickets
for help on using tickets.
Yes, I think this is a duplicate of #27697, although the desired behavior you describe isn't how Django uses model field defaults. Those defaults are only used to populate the initial the form. If a user removes that value, the default isn't called again when the form is submitted.