Date-based mixins¶
Note
All the date formatting attributes in these mixins use
strftime() format characters. Do not try to use the format
characters from the now template tag as they are not compatible.
YearMixin¶
- 
class YearMixin[source]¶
- A mixin that can be used to retrieve and provide parsing information for a year component of a date. - Methods and Attributes - 
year_format¶
- The - strftime()format to use when parsing the year. By default, this is- '%Y'.
 - 
year¶
- Optional The value for the year, as a string. By default, set to - None, which means the year will be determined using other means.
 - 
get_year_format()[source]¶
- Returns the - strftime()format to use when parsing the year. Returns- year_formatby default.
 - 
get_year()[source]¶
- Returns the year for which this view will display data, as a string. Tries the following sources, in order: - The value of the YearMixin.yearattribute.
- The value of the yearargument captured in the URL pattern.
- The value of the yearGETquery argument.
 - Raises a 404 if no valid year specification can be found. 
- The value of the 
 - 
get_next_year(date)[source]¶
- Returns a date object containing the first day of the year after the date provided. This function can also return - Noneor raise an- Http404exception, depending on the values of- allow_emptyand- allow_future.
 - 
get_previous_year(date)[source]¶
- Returns a date object containing the first day of the year before the date provided. This function can also return - Noneor raise an- Http404exception, depending on the values of- allow_emptyand- allow_future.
 
- 
MonthMixin¶
- 
class MonthMixin[source]¶
- A mixin that can be used to retrieve and provide parsing information for a month component of a date. - Methods and Attributes - 
month_format¶
- The - strftime()format to use when parsing the month. By default, this is- '%b'.
 - 
month¶
- Optional The value for the month, as a string. By default, set to - None, which means the month will be determined using other means.
 - 
get_month_format()[source]¶
- Returns the - strftime()format to use when parsing the month. Returns- month_formatby default.
 - 
get_month()[source]¶
- Returns the month for which this view will display data, as a string. Tries the following sources, in order: - The value of the MonthMixin.monthattribute.
- The value of the monthargument captured in the URL pattern.
- The value of the monthGETquery argument.
 - Raises a 404 if no valid month specification can be found. 
- The value of the 
 - 
get_next_month(date)[source]¶
- Returns a date object containing the first day of the month after the date provided. This function can also return - Noneor raise an- Http404exception, depending on the values of- allow_emptyand- allow_future.
 - 
get_previous_month(date)[source]¶
- Returns a date object containing the first day of the month before the date provided. This function can also return - Noneor raise an- Http404exception, depending on the values of- allow_emptyand- allow_future.
 
- 
DayMixin¶
- 
class DayMixin[source]¶
- A mixin that can be used to retrieve and provide parsing information for a day component of a date. - Methods and Attributes - 
day_format¶
- The - strftime()format to use when parsing the day. By default, this is- '%d'.
 - 
day¶
- Optional The value for the day, as a string. By default, set to - None, which means the day will be determined using other means.
 - 
get_day_format()[source]¶
- Returns the - strftime()format to use when parsing the day. Returns- day_formatby default.
 - 
get_day()[source]¶
- Returns the day for which this view will display data, as a string. Tries the following sources, in order: - The value of the DayMixin.dayattribute.
- The value of the dayargument captured in the URL pattern.
- The value of the dayGETquery argument.
 - Raises a 404 if no valid day specification can be found. 
- The value of the 
 - 
get_next_day(date)[source]¶
- Returns a date object containing the next valid day after the date provided. This function can also return - Noneor raise an- Http404exception, depending on the values of- allow_emptyand- allow_future.
 - 
get_previous_day(date)[source]¶
- Returns a date object containing the previous valid day. This function can also return - Noneor raise an- Http404exception, depending on the values of- allow_emptyand- allow_future.
 
- 
WeekMixin¶
- 
class WeekMixin[source]¶
- A mixin that can be used to retrieve and provide parsing information for a week component of a date. - Methods and Attributes - 
week_format¶
- The - strftime()format to use when parsing the week. By default, this is- '%U', which means the week starts on Sunday. Set it to- '%W'if your week starts on Monday.
 - 
week¶
- Optional The value for the week, as a string. By default, set to - None, which means the week will be determined using other means.
 - 
get_week_format()[source]¶
- Returns the - strftime()format to use when parsing the week. Returns- week_formatby default.
 - 
get_week()[source]¶
- Returns the week for which this view will display data, as a string. Tries the following sources, in order: - The value of the WeekMixin.weekattribute.
- The value of the weekargument captured in the URL pattern
- The value of the weekGETquery argument.
 - Raises a 404 if no valid week specification can be found. 
- The value of the 
 - 
get_next_week(date)[source]¶
- Returns a date object containing the first day of the week after the date provided. This function can also return - Noneor raise an- Http404exception, depending on the values of- allow_emptyand- allow_future.
 - 
get_prev_week(date)¶
- Returns a date object containing the first day of the week before the date provided. This function can also return - Noneor raise an- Http404exception, depending on the values of- allow_emptyand- allow_future.
 
- 
DateMixin¶
- 
class DateMixin[source]¶
- A mixin class providing common behavior for all date-based views. - Methods and Attributes - 
date_field¶
- The name of the - DateFieldor- DateTimeFieldin the- QuerySet’s model that the date-based archive should use to determine the list of objects to display on the page.- When time zone support is enabled and - date_fieldis a- DateTimeField, dates are assumed to be in the current time zone. Otherwise, the queryset could include objects from the previous or the next day in the end user’s time zone.- Warning - In this situation, if you have implemented per-user time zone selection, the same URL may show a different set of objects, depending on the end user’s time zone. To avoid this, you should use a - DateFieldas the- date_fieldattribute.
 - 
allow_future¶
- A boolean specifying whether to include “future” objects on this page, where “future” means objects in which the field specified in - date_fieldis greater than the current date/time. By default, this is- False.
 - 
get_date_field()[source]¶
- Returns the name of the field that contains the date data that this view will operate on. Returns - date_fieldby default.
 - 
get_allow_future()[source]¶
- Determine whether to include “future” objects on this page, where “future” means objects in which the field specified in - date_fieldis greater than the current date/time. Returns- allow_futureby default.
 
- 
BaseDateListView¶
- 
class BaseDateListView[source]¶
- A base class that provides common behavior for all date-based views. There won’t normally be a reason to instantiate - BaseDateListView; instantiate one of the subclasses instead.- While this view (and its subclasses) are executing, - self.object_listwill contain the list of objects that the view is operating upon, and- self.date_listwill contain the list of dates for which data is available.- Mixins - Methods and Attributes - 
allow_empty¶
- A boolean specifying whether to display the page if no objects are available. If this is - Trueand no objects are available, the view will display an empty page instead of raising a 404.- This is identical to - django.views.generic.list.MultipleObjectMixin.allow_empty, except for the default value, which is- False.
 - 
date_list_period¶
- Optional A string defining the aggregation period for - date_list. It must be one of- 'year'(default),- 'month', or- 'day'.
 - 
get_dated_items()[source]¶
- Returns a 3-tuple containing ( - date_list,- object_list,- extra_context).- date_listis the list of dates for which data is available.- object_listis the list of objects.- extra_contextis a dictionary of context data that will be added to any context data provided by the- MultipleObjectMixin.
 - 
get_dated_queryset(**lookup)[source]¶
- Returns a queryset, filtered using the query arguments defined by - lookup. Enforces any restrictions on the queryset, such as- allow_emptyand- allow_future.
 - 
get_date_list_period()[source]¶
- Returns the aggregation period for - date_list. Returns- date_list_periodby default.
 - 
get_date_list(queryset, date_type=None, ordering='ASC')[source]¶
- Returns the list of dates of type - date_typefor which- querysetcontains entries. For example,- get_date_list(qs, 'year')will return the list of years for which- qshas entries. If- date_typeisn’t provided, the result of- get_date_list_period()is used.- date_typeand- orderingare simply passed to- QuerySet.dates().
 
- 
 
          