mirror of https://github.com/django/django.git
Fixed #15566 - Documented that update() doesn't honor DateField.auto_now
Thanks Shabda Raaj for the draft patch.
This commit is contained in:
parent
09a99714c0
commit
dc01e41d23
|
@ -181,10 +181,10 @@ card values plus their suits; 104 characters in total.
|
||||||
Many of Django's model fields accept options that they don't do anything
|
Many of Django's model fields accept options that they don't do anything
|
||||||
with. For example, you can pass both
|
with. For example, you can pass both
|
||||||
:attr:`~django.db.models.Field.editable` and
|
:attr:`~django.db.models.Field.editable` and
|
||||||
:attr:`~django.db.models.Field.auto_now` to a
|
:attr:`~django.db.models.DateField.auto_now` to a
|
||||||
:class:`django.db.models.DateField` and it will simply ignore the
|
:class:`django.db.models.DateField` and it will simply ignore the
|
||||||
:attr:`~django.db.models.Field.editable` parameter
|
:attr:`~django.db.models.Field.editable` parameter
|
||||||
(:attr:`~django.db.models.Field.auto_now` being set implies
|
(:attr:`~django.db.models.DateField.auto_now` being set implies
|
||||||
``editable=False``). No error is raised in this case.
|
``editable=False``). No error is raised in this case.
|
||||||
|
|
||||||
This behavior simplifies the field classes, because they don't need to
|
This behavior simplifies the field classes, because they don't need to
|
||||||
|
@ -516,8 +516,8 @@ for the first time, the ``add`` parameter will be ``True``, otherwise it will be
|
||||||
You only need to override this method if you want to preprocess the value
|
You only need to override this method if you want to preprocess the value
|
||||||
somehow, just before saving. For example, Django's
|
somehow, just before saving. For example, Django's
|
||||||
:class:`~django.db.models.DateTimeField` uses this method to set the attribute
|
:class:`~django.db.models.DateTimeField` uses this method to set the attribute
|
||||||
correctly in the case of :attr:`~django.db.models.Field.auto_now` or
|
correctly in the case of :attr:`~django.db.models.DateField.auto_now` or
|
||||||
:attr:`~django.db.models.Field.auto_now_add`.
|
:attr:`~django.db.models.DateField.auto_now_add`.
|
||||||
|
|
||||||
If you do override this method, you must return the value of the attribute at
|
If you do override this method, you must return the value of the attribute at
|
||||||
the end. You should also update the model's attribute if you make any changes
|
the end. You should also update the model's attribute if you make any changes
|
||||||
|
|
|
@ -968,11 +968,12 @@ Be aware that the ``update()`` method is converted directly to an SQL
|
||||||
statement. It is a bulk operation for direct updates. It doesn't run any
|
statement. It is a bulk operation for direct updates. It doesn't run any
|
||||||
:meth:`~django.db.models.Model.save` methods on your models, or emit the
|
:meth:`~django.db.models.Model.save` methods on your models, or emit the
|
||||||
``pre_save`` or ``post_save`` signals (which are a consequence of calling
|
``pre_save`` or ``post_save`` signals (which are a consequence of calling
|
||||||
:meth:`~django.db.models.Model.save`). If you want to save every item in a
|
:meth:`~django.db.models.Model.save`), or honor the
|
||||||
:class:`~django.db.models.query.QuerySet` and make sure that the
|
:attr:`~django.db.models.DateField.auto_now` field option.
|
||||||
:meth:`~django.db.models.Model.save` method is called on each instance, you
|
If you want to save every item in a :class:`~django.db.models.query.QuerySet`
|
||||||
don't need any special function to handle that. Just loop over them and call
|
and make sure that the :meth:`~django.db.models.Model.save` method is called on
|
||||||
:meth:`~django.db.models.Model.save`::
|
each instance, you don't need any special function to handle that. Just loop
|
||||||
|
over them and call :meth:`~django.db.models.Model.save`::
|
||||||
|
|
||||||
for item in my_queryset:
|
for item in my_queryset:
|
||||||
item.save()
|
item.save()
|
||||||
|
|
Loading…
Reference in New Issue