Class-based generic views

Note

This documentation only documents the differences between Django and Tincture. For all other functionality, see Django’s documentation.

Mixins

Session

SessionMixin

class tincture.views.generic.session.SessionMixin
session

A SQLAlchemy session instance.

get_session()

Returns a SQLAlchemy session instance. By default, this returns SessionMixin.session.

Single object mixins

SingleObjectMixin

class tincture.views.generic.detail.SingleObjectMixin
model

The SQLAlchemy model that this view will display data for. Specifying model = Foo is effectively the same as specifying query_object = session.query(Foo).

query_object

A SQLAlchemy Query object.

See Django’s SingleObjectMixin.queryset.

session

A SQLAlchemy Session instance. This session will be used to generate a Query object for the view.

pk_url_kwargs

A tuple of URLconf keword argument names that comprise the primary key. The default is ('pk',). Note that this is named differently from Django’s SingleObjectMixin.pk_url_kwarg.

get_object(query_object=None)

Returns the single object this view will display. If query_object is provided, it will be used to obtain the object. Otherwise, get_query_object() will be used.

get_query_object()

Returns the SQLAlchemy Query object that represents the data this view will display.

See Django’s SingleObjectMixin.get_queryset.

SingleObjectTemplateResponseMixin

class tincture.views.generic.detail.SingleObjectTemplateResponseMixin
get_template_names()

Returns a list of template names. In addition to the template names from Django that aren’t based on the model, this returns:

  • <lowercase model class name><template_name_suffix>.html

Note

With SQLAlchemy there’s no built-in way to detect an app name, so you may want to provide your own implementation of this method to make template discovery more robust.

See Django’s SingleObjectTemplateResponseMixin.get_template_names.

Multiple object mixins

MultipleObjectMixin

class tincture.views.generic.list.MultipleObjectMixin
model

The SQLAlchemy model that this view will display data for. Specifying model = Foo is effectively the same as specifying query_object = session.query(Foo).

query_object

A SQLAlchemy Query object.

See Django’s MultipleObjectMixin.queryset.

session

A SQLAlchemy Session instance. This session will be used to generate a Query object for the view.

get_query_object()

Returns the SQLAlchemy Query object that represents the data this view will display.

See Django’s MultipleObjectMixin.get_queryset.

paginate_query_object(query_object, page_size)

See Django’s MultipleObjectMixin.paginate_queryset.

get_paginate_by(query_object)

See Django’s MultipleObjectMixin.get_paginate_by.

get_paginator(query_object, per_page, orphans=0, allow_empty_first_page=True)

See Django’s MultipleObjectMixin.get_paginator.

get_context_object_name(object_list)

Returns the context variable name that will be used to contain the list of data that this view is manipulating. If object_list is a SQLAlchemy Query object, it’ll use the lowercased name of the first entity in the query. For example, a query for the Person and Dog models will return ‘person_list’.

MultipleObjectTemplateResponseMixin

class tincture.views.generic.list.MultipleObjectTemplateResponseMixin
get_template_names()

Returns a list of template names. In addition to the template names from Django that aren’t based on the model, this returns:

  • <lowercase model class name><template_name_suffix>.html

The Query object’s first entity is used to retrieve the class name used here.

Note

With SQLAlchemy there’s no built-in way to detect an app name, so you may want to provide your own implementation of this method to make template discovery more robust.

See Django’s MultipleObjectTemplateResponseMixin.get_template_names.

Generic views

Detail views

DetailView

class tincture.views.generic.detail.BaseDetailView
class tincture.views.generic.detail.DetailView

See Django’s DetailView.

Mixins

List views