Single object mixins¶
- class django.views.generic.detail.SingleObjectMixin¶
Provides a mechanism for looking up an object associated with the current HTTP request.
Methods and Attributes
The model that this view will display data for. Specifying model = Foo is effectively the same as specifying queryset = Foo.objects.all().
A QuerySet that represents the objects. If provided, the value of queryset supersedes the value provided for model.
The name of the field on the model that contains the slug. By default, slug_field is 'slug'.
The name of the URLConf keyword argument that contains the slug. By default, slug_url_kwarg is 'slug'.
The name of the URLConf keyword argument that contains the primary key. By default, pk_url_kwarg is 'pk'.
Designates the name of the variable to use in the context.
Returns the single object that this view will display. If queryset is provided, that queryset will be used as the source of objects; otherwise, get_queryset() will be used. get_object() looks for a pk_url_kwarg argument in the arguments to the view; if this argument is found, this method performs a primary-key based lookup using that value. If this argument is not found, it looks for a slug_url_kwarg argument, and performs a slug lookup using the slug_field.
Returns the queryset that will be used to retrieve the object that this view will display. By default, get_queryset() returns the value of the queryset attribute if it is set, otherwise it constructs a QuerySet by calling the all() method on the model attribute’s default manager.
Return the context variable name that will be used to contain the data that this view is manipulating. If context_object_name is not set, the context name will be constructed from the model_name of the model that the queryset is composed from. For example, the model Article would have context object named 'article'.
Returns context data for displaying the list of objects.
Returns the name of a slug field to be used to look up by slug. By default this simply returns the value of slug_field.
- object: The object that this view is displaying. If context_object_name is specified, that variable will also be set in the context, with the same value as object.
- class django.views.generic.detail.SingleObjectTemplateResponseMixin¶
A mixin class that performs template-based response rendering for views that operate upon a single object instance. Requires that the view it is mixed with provides self.object, the object instance that the view is operating on. self.object will usually be, but is not required to be, an instance of a Django model. It may be None if the view is in the process of constructing a new instance.
Methods and Attributes
The field on the current object instance that can be used to determine the name of a candidate template. If either template_name_field itself or the value of the template_name_field on the current object instance is None, the object will not be used for a candidate template name.
The suffix to append to the auto-generated candidate template name. Default suffix is _detail.
Returns a list of candidate template names. Returns the following list:
- the value of template_name on the view (if provided)
- the contents of the template_name_field field on the object instance that the view is operating upon (if available)
Having trouble? We'd like to help!
- Try the FAQ — it's got answers to many common questions.
- Search for information in the archives of the django-users mailing list, or post a question.
- Ask a question in the #django IRC channel, or search the IRC logs to see if it has been asked before.
- If you notice errors with this documentation, please open a ticket and let us know! Please only use the ticket tracker for criticisms and improvements on the docs. For tech support, use the resources above.