How it works...

The CreationModificationDateMixin class is an abstract model, which means that extending model classes will create all of the fields in the same database table—that is, there will be no one-to-one relationships that make the table more complex to handle.

This mixin has two date-time fields, created and modifiedWith the auto_now_add and auto_now attributes, the timestamps will be saved automatically when saving a model instance. The fields will automatically get the editable=False attribute, and thus will be hidden in administration forms. If USE_TZ is set to True in the settings (which is the default and recommended), time-zone-aware timestamps will be used. Otherwise, time-zone-naive timestamps will be used. Timezone-aware timestamps are saved in the Coordinated Universal Time (UTC) time zone in the database and converted to the default time zone of the project when reading or writing them. Time-zone-naive timestamps are saved in the local time zone of the project in the database; they are not practical to use in general, because they make time management between time zones more complicated.

To make use of this mixin, we just have to import it and extend our model, as follows:

# myproject/apps/ideas/models.py
from django.db import models

from myproject.apps.core.models import CreationModificationDateBase

class Idea(CreationModificationDateBase):
# other fields, attributes, properties, and methods…
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.143.168.172