27medkamal / djangorestframework-fsm Goto Github PK
View Code? Open in Web Editor NEWAutomatically hook your Django-FSM transitions up to Django REST Framework
License: MIT License
Automatically hook your Django-FSM transitions up to Django REST Framework
License: MIT License
Hey there,
I've made some transitions in a data model called "Article". But when I try to integrate it in an existing REST API I've constructed for Article, it does not show up in Swagger. Here is what I do:
from rest_framework import generics, mixins
from djangorestframework_fsm.viewset_mixins import get_drf_fsm_mixin
from .models import Article
class ArticleAPIView (
get_drf_fsm_mixin(Article, fieldname='status'),
mixins.UpdateModelMixin,
generics.RetrieveAPIView,
):
// . . .
If I add the viewset, as show below:
from rest_framework import generics, mixins
from djangorestframework_fsm.viewset_mixins import get_drf_fsm_mixin
from .models import Article
from rest_framework import viewsets
class ArticleAPIView (
get_drf_fsm_mixin(Article, fieldname='status'),
mixins.UpdateModelMixin,
generics.RetrieveAPIView,
viewsets.ModelViewSet,
):
it throws the following error: TypeError: Cannot create a consistent method resolution order (MRO) for bases object, UpdateModelMixin, RetrieveAPIView, ModelViewSet
How do I integrate this properly?
P.S.: The order of the generics and mixins is not making a difference.
With DRF 3.9.0 the mapping mechanics have changed. To have the transition_action mapped to the transitions’ names I added the following code:
# DRF 3.9 introduces a new mapper.
# Unfortunately this mapper uses the function’s default name, here: "transition_action"
# Thus we have to overwrite all values with the transition name.
transition_action.__name__ = transition_name
transition_action.mapping = dict.fromkeys(transition_action.mapping, transition_name)
Would you accept a PR that adds an option to wrap the calls to the transition (and save if configured) with a with transaction.atomic()
? If your transition creates or mutations data in other models, a transaction is needed to ensure integrity.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.