django_sorcery.viewsets package

class django_sorcery.viewsets.GenericViewSet(**kwargs)[source]

Bases: django.views.generic.base.TemplateResponseMixin, django.views.generic.base.View

Base class for all sqlalchemy model generic viewsets.

classmethod as_view(actions=None, **initkwargs)[source]

Main entry point for a request-response process.

classmethod get_extra_actions()[source]

Get the methods that are marked as an extra ViewSet @action.

get_template_names()[source]

Return a list of template names to be used for the request. Must return a list. May not be called if render_to_response() is overridden.

class django_sorcery.viewsets.ModelViewSet(**kwargs)[source]

Bases: django_sorcery.viewsets.mixins.CreateModelMixin, django_sorcery.viewsets.mixins.UpdateModelMixin, django_sorcery.viewsets.mixins.DeleteModelMixin, django_sorcery.viewsets.base.ReadOnlyModelViewSet

A viewset that provides default new(), create(), retrieve(), edit(), update()`, confirm_destroy()), destroy() and list() actions.

When used with router, it will map the following operations to actions on the viewset

Method Path Action Route Name
GET / list <resource name>-list
POST / create <resource name>-list
GET /new/ new <resource name>-new
GET /<pk>/ retrieve <resource name>-detail
POST /<pk>/ update <resource name>-detail
PUT /<pk>/ update <resource name>-detail
PATCH /<pk>/ update <resource name>-detail
DELETE /<pk>/ destroy <resource name>-detail
GET /<pk>/edit/ edit <resource name>-edit
GET /<pk>/delete/ confirm_destoy <resource name>-delete
POST /<pk>/delete/ destroy <resource name>-delete
class django_sorcery.viewsets.ReadOnlyModelViewSet(**kwargs)[source]

Bases: django_sorcery.viewsets.mixins.ListModelMixin, django_sorcery.viewsets.mixins.RetrieveModelMixin, django_sorcery.viewsets.base.GenericViewSet

A viewset that provides default list() and retrieve() actions.

When used with router, it will map the following operations to actions on the viewset

Method Path Action Route Name
GET / list <resource name>-list
GET /<pk>/ retrieve <resource name>-detail
class django_sorcery.viewsets.CreateModelMixin[source]

Bases: django_sorcery.viewsets.mixins.ModelFormMixin

A mixin for supporting creating objects.

When used with router, it will map the following operations to actions on the viewset

Method Path Action Route Name
POST / create <resource name>-list
GET /new/ new <resource name>-new
create(request, *args, **kwargs)[source]

Create action for creating an object.

get_create_context_data(**kwargs)[source]

Returns new context data for template rendering.

new(request, *args, **kwargs)[source]

New action for displaying a form for creating an object.

class django_sorcery.viewsets.DeleteModelMixin[source]

Bases: django_sorcery.viewsets.mixins.RetrieveModelMixin

A mixin for supporting deleting objects.

When used with router, it will map the following operations to actions on the viewset

Method Path Action Route Name
GET /<pk>/delete/ confirm_destoy <resource name>-delete
POST /<pk>/delete/ destroy <resource name>-delete
DELETE /<pk>/ destroy <resource name>-detail
confirm_destroy(request, *args, **kwargs)[source]

Confirm_destory action for displaying deletion confirmation for an object.

destroy(request, *args, **kwargs)[source]

Destroy action for deletion of an object.

destroy_success_url = None
get_destroy_context_data(**kwargs)[source]

Returns destory context data for rendering deletion confirmation page.

get_destroy_success_url()[source]

Return the url to redirect to after successful deletion of an object.

perform_destoy(obj)[source]

Performs the deletion operation.

class django_sorcery.viewsets.ListModelMixin[source]

Bases: django_sorcery.views.base.BaseMultipleObjectMixin

A mixin for displaying a list of objects.

When used with router, it will map the following operations to actions on the viewset

Method Path Action Route Name
GET / list <resource name>-list
get_list_context_data(**kwargs)[source]

Returns context data for list action.

get_list_context_object_name(object_list)[source]

Get the name to use for the object.

list(request, *args, **kwargs)[source]

List action for displaying a list of objects.

class django_sorcery.viewsets.ModelFormMixin[source]

Bases: django.views.generic.edit.FormMixin, django_sorcery.viewsets.mixins.RetrieveModelMixin

Common mixin for handling sqlalchemy model forms in viewsets.

fields = None
form_class = None
form_invalid(form)[source]

Handles invalid form.

form_valid(form)[source]

Processes a valid form.

get_form_class()[source]

Returns the form class to be used.

get_form_context_data(**kwargs)[source]

Return form context data for template rendering.

get_form_kwargs()[source]

Returns the keyword arguments for instantiating the form.

get_success_url()[source]

Return the URL to redirect to after processing a valid form.

process_form(form)[source]

Checks if form is valid and processes accordingly.

success_url = None
class django_sorcery.viewsets.RetrieveModelMixin[source]

Bases: django_sorcery.views.base.BaseSingleObjectMixin

A mixin for displaying a single object.

When used with router, it will map the following operations to actions on the viewset

Method Path Action Route Name
GET /<pk>/ retrieve <resource name>-detail
get_detail_context_data(**kwargs)[source]

Returns detail context data for template rendering.

get_detail_context_object_name(obj)[source]

Get the name to use for the object.

get_url_kwargs(obj)[source]
retrieve(request, *args, **kwargs)[source]

List action for displaying a single object.

class django_sorcery.viewsets.UpdateModelMixin[source]

Bases: django_sorcery.viewsets.mixins.ModelFormMixin

A mixin for supporting updating objects.

When used with router, it will map the following operations to actions on the viewset

Method Path Action Route Name
GET /<pk>/edit/ edit <resource name>-edit
POST /<pk>/ update <resource name>-detail
PUT /<pk>/ update <resource name>-detail
PATCH /<pk>/ update <resource name>-detail
edit(request, *args, **kwargs)[source]

Edit action for displaying a form for editing an object.

get_update_context_data(**kwargs)[source]

Returns edit context data for template rendering.

update(request, *args, **kwargs)[source]

Update action for updating an object.