#30401: Clarification about when a default value is assigned to a ModelField
------------------------------------------------+------------------------
Reporter: viniciusban | Owner: nobody
Type: Cleanup/optimization | Status: new
Component: Documentation | Version: 2.2
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
------------------------------------------------+------------------------
The documentation says in
https://docs.djangoproject.com/en/2.2/ref/models/fields/#default at the
first paragraph:
The default value for the field. This can be a value or a callable
object. If callable it will be called every time a new object is created.
My suggestion is to change the last word above, from "created" to
"instantiated" or to "instantiated in memory".
"Created" is confusing with `QuerySet.create()` method, leading to the
misunderstanding about when the default value is assigned to field.
I myself misunderstood I could use the traditional approach to check if
performing an insert or an update in `Model.save()` with `if self.pk is
None` when my pk is an `UUIDField` with `default=uuid.uuid4`.
--
Ticket URL: <https://code.djangoproject.com/ticket/30401>
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 post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/054.3b5051cb61b6e6e4fdd749d0b9cf6000%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.