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 0x7f2e9bb9b240> DateMixin
Expand Collapse

Methods

def get_allow_future(self): DateMixin

Return `True` if the view should be allowed to display objects from
the future.
240
241
242
243
244
245
def get_allow_future(self):
    """
    Return `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.
234
235
236
237
238
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

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.
260
261
262
263
264
265
266
267
268
269
270
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.
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
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}