Code Monkey home page Code Monkey logo

djangorestframework-fsm's People

Contributors

27medkamal avatar bashu avatar fladi avatar jacobh avatar sirmaahe avatar yard1 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

djangorestframework-fsm's Issues

Not hooking up to existing REST API

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.

DRF 3.9.0: new MethodMapper

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)

Optional transaction.atomic()?

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.