Skip to content
This repository has been archived by the owner on May 25, 2023. It is now read-only.

Automatically hook your Django-FSM transitions up to Django REST Framework

License

Notifications You must be signed in to change notification settings

GradConnection/drf-fsm-transitions

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

drf-fsm-transitions

Automatically hook your Django-FSM transitions up to Django REST Framework

Installation

pip install drf-fsm-transitions

Usage

When declaring your viewset, simply mix in the result of get_viewset_transition_action_mixin

from rest_framework import viewsets
from drf_transition_methods.viewset_mixins import get_viewset_transition_action_mixin

from .models import Article


class ArticleViewSet(
    get_viewset_transition_action_mixin(Article),
    viewsets.ModelViewSet
):
    queryset = Article.objects.all()

if Article had 2 transitions, delete and publish, the following API calls would be set up

  • POST /api/article/1234/delete/
  • POST /api/article/1234/publish/

Saving

By default, the model instance will be saved after the transition has been successfully called. This can be disabled with the save_after_transition attribute

class ArticleViewSet(
    get_viewset_transition_action_mixin(Article),
    viewsets.ModelViewSet
):
    queryset = Article.objects.all()
    save_after_transition = False

About

Automatically hook your Django-FSM transitions up to Django REST Framework

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Python 100.0%