5.4. Models Field Date

  • models.DateTimeField - stores both date and time, represented in Python by a datetime.datetime instance

  • models.DateField - stores the date, represented in Python by a datetime.date instance

  • models.TimeField - stores the time, represented in Python by a datetime.time instance

  • models.DurationField - stores a period of time, represented in Python by a datetime.timedelta instance

>>> 
... from django.db import models
... from django.utils.translation import gettext_lazy as _
...
...
... class Customer(models.Model):
...     creation_date = models.DateTimeField(verbose_name=_('Creation Date'), auto_now_add=True, editable=False)
...     modification_date = models.DateTimeField(verbose_name=_('Modification Date'), auto_now=True)
...     birthdate = models.DateField(verbose_name=_('Birthdate'), null=True, blank=True, default=None)
...
...     class Meta:
...         verbose_name = _('Customer')
...         verbose_name_plural = _('Customer')
...
...    def __str__(self):
...         return f'{self.firstname} {self.lastname}'

5.4.1. Arguments

  • auto_add (DateField, DateTimeField)

  • auto_add_now (DateField, DateTimeField)

  • blank

  • choices

  • db_column

  • db_index

  • default

  • editable

  • error_message

  • help_text

  • limit_choices_to

  • max_length

  • null

  • primary_key

  • unique

  • validators

  • verbose_name