Django admin - enable manual editing of autoTimeTime fields

Is it possible to enable manual editing of automatic DateTimeField on the add / change model page. Fields are defined as:

post_date = models.DateTimeField(auto_now_add=True)
post_updated = models.DateTimeField(auto_now=True)

I'm not sure how this will work manually, is this an automatic update performed at the database level or in the django itself?

+3
source share
2 answers

auto_now_add=Trueand auto_now=True accept editable=False . Therefore, if you need to correct this field, do not use them.

Automatic descriptor update at django level. For example, if you update a query, for example,

Article.object.filter(pk=10).update(active=True)

will not update the field post_updated. But

article = Article.object.get(pk=10)
article.active = True
atricle.save()

will make

+2
source

auto_now_add=True auto_now=True editable=False. , ModelForm, auto_now_*=True.

auto_now_* Django.

auto_now_*=True, Django , ,

class Article(models.Model):
    active = models.BooleanField()
    updated = models.DateTimeField(auto_now=True)
article = Article.object.get(pk=10)
article.active = True
article.save()
# ASSERT: article.updated has been automatically updated with the current date and time

Django, , queryset.update(), ,

Article.object.filter(pk=10).update(active=True)
# ASSERT: Article.object.get(pk=10).updated is unchanged

import datetime
Article.object.filter(pk=10).update(updated=datetime.datetime(year=2014, month=3, day=21))
# ASSERT: article.updated == March 21, 2014
0

All Articles