On Aug 3, 2015 3:36 AM, "Anssi Kääriäinen" <akaar...@gmail.com> wrote:
>
> On Wednesday, July 29, 2015 at 8:05:10 AM UTC+3, Aron Podrigal wrote:
>>
>> I would like to propose making Fields.default to rely on the database
generated defaults where possible. This could be implemented by having
some  constants like fields.CURRENT_TIMESTAMP, etc.  The tricky part here
is to detect database backend specific capabilities and have a python
equivalent fallback.
>>
>> Any thoughts?
>
>
> A couple of questions about this:
>   - What should happen when you instantiate a new model with DB default,
and show that model to the user in a form. Is the field shown to the user,
and if so, what value should it have?

The field would have no value, so when displayed on the form it would be
blank. A field with blank=False which is included in a form, having a
db_default would be useless.

>   - How to implement actual fetching of the values after save() -
PostgreSQL supports RETURNING, but this is not the case for all databases.

The value would be fetched on demand on its first access, saving a trip to
the database if the field is not accessed. Subsequent updates on that
instance would leave out that field from the list of fields to be updated,
unless its value has been changed on the instance. Maybe we can allow to
handle this based on some parameter provided to save() ?

>   - When is the default applied? On first save of the model, or on model
init time?

Of course on first save, as we want the default value atomically within the
same transaction.

>   - Do we want to allow extending this to defaults that are applied on
every save (automatic database backed modified timestamps for example)?

+1 for this one too.

>
>  - Anssi
>
> --
> You received this message because you are subscribed to the Google Groups
"Django developers (Contributions to Django itself)" group.
> To unsubscribe from this group and stop receiving emails from it, send an
email to django-developers+unsubscr...@googlegroups.com.
> To post to this group, send email to django-developers@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-developers.
> To view this discussion on the web visit
https://groups.google.com/d/msgid/django-developers/f1a7cc68-de1a-49f8-bdf8-ebfaade59955%40googlegroups.com
.
>
> For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups 
"Django developers  (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-developers+unsubscr...@googlegroups.com.
To post to this group, send email to django-developers@googlegroups.com.
Visit this group at http://groups.google.com/group/django-developers.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-developers/CANJp-yhtS4xVy4MLoOs%2B0%2B_9AnkZqmpw%2BVmG8pO%3DQ%2Byda01yAA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to