Opened 5 years ago
Closed 5 years ago
#30969 closed Uncategorized (duplicate)
Add support for query expressions as default values
Reported by: | Johannes Maron | Owned by: | Johannes Maron |
---|---|---|---|
Component: | Database layer (models, ORM) | Version: | dev |
Severity: | Normal | Keywords: | |
Cc: | Triage Stage: | Unreviewed | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description (last modified by )
Add support for query expressions – like Now()
– as default values of model fields.
e.g.
class MyModel(models.Model): created = models.DateTimeField(default=models.Now())
This was originally part of my patch for https://code.djangoproject.com/ticket/29444, but I deferred it to keep the changeset more moderate.
There are a couple things here to consider:
- This feature will only be supported in PostgreSQL and Oracle. Other Databases do allow setting defaults, but can not return them on insert.
- Since the default is provided by the database, fields with a query expression as a default should default not to be editable. This will avoid confusion in interfaces like, Django admin, since these fields will be empty upon insert and then magically have a value. This is behavior would be consistent with the auto increment fields.
Since I extracted this from another feature branch, the patch is already done. I will link it, as it might help to understand the proposal a bit better.
This is the current patch:
https://github.com/django/django/pull/11783
Change History (4)
comment:1 by , 5 years ago
Description: | modified (diff) |
---|---|
Has patch: | set |
comment:2 by , 5 years ago
Owner: | changed from | to
---|---|
Status: | new → assigned |
comment:3 by , 5 years ago
comment:4 by , 5 years ago
Resolution: | → duplicate |
---|---|
Status: | assigned → closed |
Definitely, thanks Baptiste.
Duplicate of #30032.
Is this ticket a duplicate of #30032?