class DateMixin

from django.views.generic.dates import DateMixin
Hierarchy diagram Documentation Source code
Mixin class for views manipulating date-based data.

Attributes

  Defined in
allow_future = False DateMixin
date_field = None DateMixin
uses_datetime_field = <django.utils.functional.cached_property object at 0x7f8f33e28128> DateMixin
Expand Collapse

Methods

def _make_date_lookup_arg(self, value): DateMixin

Convert a date into a datetime when the date field is a DateTimeField.

When time zone support is enabled, `date` is assumed to be in the
current time zone, so that displayed items are consistent with the URL.
307
308
309
310
311
312
313
314
315
316
317
def _make_date_lookup_arg(self, value):
    """
    Convert a date into a datetime when the date field is a DateTimeField.
    When time zone support is enabled, `date` is assumed to be in the
    current time zone, so that displayed items are consistent with the URL.
    """
    if self.uses_datetime_field:
        value = datetime.datetime.combine(value, datetime.time.min)
        if settings.USE_TZ:
            value = timezone.make_aware(value, timezone.get_current_timezone())
    return value

def _make_single_date_lookup(self, date): DateMixin

Get the lookup kwargs for filtering on a single date.

If the date field is a DateTimeField, we can't just filter on
date_field=date because that doesn't take the time into account.
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
def _make_single_date_lookup(self, date):
    """
    Get the lookup kwargs for filtering on a single date.
    If the date field is a DateTimeField, we can't just filter on
    date_field=date because that doesn't take the time into account.
    """
    date_field = self.get_date_field()
    if self.uses_datetime_field:
        since = self._make_date_lookup_arg(date)
        until = self._make_date_lookup_arg(date + datetime.timedelta(days=1))
        return {
            '%s__gte' % date_field: since,
            '%s__lt' % date_field: until,
        }
    else:
        # Skip self._make_date_lookup_arg, it's a no-op in this branch.
        return {date_field: date}

def get_allow_future(self): DateMixin

Returns `True` if the view should be allowed to display objects from
the future.
287
288
289
290
291
292
def get_allow_future(self):
    """
    Returns `True` if the view should be allowed to display objects from
    the future.
    """
    return self.allow_future

def get_date_field(self): DateMixin

Get the name of the date field to be used to filter by.
279
280
281
282
283
284
285
def get_date_field(self):
    """
    Get the name of the date field to be used to filter by.
    """
    if self.date_field is None:
        raise ImproperlyConfigured("%s.date_field is required." % self.__class__.__name__)
    return self.date_field