#35659: Document db_default behaviour before instances are saved
-------------------------------------+-------------------------------------
Reporter: Markus Andresen | Owner: Jerome
Type: | Cagado
Cleanup/optimization | Status: assigned
Component: Documentation | Version: 5.0
Severity: Normal | Resolution:
Keywords: db_default | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by Simon Charette):
My concerns with specializing `DatabaseDefault.__bool__` (or even just for
conditional `output_field = BooleanField()` expressions) would be that
this would create an asymmetry with other expression assignments which are
refreshed on `Model.save` now.
{{{#!python
from django.db import models
class MyModel(models.Model):
my_field = models.BooleanField()
my_obj = MyModel()
my_obj.my_field = Value(False) # Or any expression really such as
`GreaterThan(Now(), some_datetime))
bool(my_obj.my_field) # True
my_obj.save()
bool(my_obj.my_field) # False
}}}
To me it is just bad practice to expect model fields assignments to always
be literal values as assigning expressions is just as valid hence why I
think it's more of a documentation issue.
--
Ticket URL: <https://code.djangoproject.com/ticket/35659#comment:9>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion visit
https://groups.google.com/d/msgid/django-updates/01070199d2e4bfe1-7d5390c4-4f24-4f07-af05-f1a3d2b4e077-000000%40eu-central-1.amazonses.com.