Detail views

Views

BaseDetailView

class flask_views.db.mongoengine.detail.BaseDetailView

Base detail view.

This class inherits from:

This class implements all logic for retrieving a single object from the database, but does not implement rendering responses. See DetailView for an usage example.

get(*args, **kwargs)

Handler for GET requests.

This retrieves the object from the database and calls the render_to_response with the retrieved object in the context data.

Returns:Ouput of render_to_response method implementation.

DetailView

class flask_views.db.mongoengine.detail.DetailView

Detail view for rendering an object.

This class inherits from:

This class implements all logic for retrieving a single object from the database, including rendering a template.

Usage example:

class ArticleView(DetailView):
    get_fields = {
        'category': 'category',
        'slug': 'slug',
    }
    document_class = Article
    template_name = 'article_detail.html'

Mixins

SingleObjectMixin

class flask_views.db.mongoengine.detail.SingleObjectMixin

Mixin for retrieving a single object from the database.

context_object_name = None

The variable name to give this object in the template context. If None, it will get the name of the model class (Eg: a class Page would be available as page).

document_class = None

Document class from which the object should be retrieved.

get_context_data(**kwargs)

Return context data containing the retrieved object.

Returns:A dict containing the retrieved object.
get_context_object_name()

Return the context object name.

If SingleObjectMixin.context_object_name is set, that value will be returned, else it will use the lowercased name of the model set in SingleObjectMixin.document_class.

Returns:A str representing the object name.
get_fields = {'id': 'id'}

A dict containing the fieldname mapped against the URL variable name. For example when you have the URL route '/<category>/<author>/', and the following setting:

get_fields = {
    'cat': 'category',
    'user': 'author',
}

When requesting /news/john/, it would perform the following query: get(cat='news', user='john').

get_object()

Retrieve the object from the database.

Returns:An instance of the model class containing the retrieved object.
Raise :werkzeug.exceptions.NotFound when the document does not exist.
get_queryset()

Return QuerySet class used to retrieve objects.

Returns:An instance of mongoengine.queryset.QuerySet.

Table Of Contents

Related Topics

This Page