sainipray / drf-fsm

Create Django FSM transitions as a endpoint with Django REST Framework
MIT License
4 stars 0 forks source link

no methods for status change #1

Open shadeimi opened 2 years ago

shadeimi commented 2 years ago

Using the provided tutorial and drf-spectacular as swagger layer, i don' see any endpoint about state change

drf-fsm = 1.0.4 django = 4.0.6

sainipray commented 2 years ago

I updated the flow now, You will only have one endpoint that will handle the automatic transition, you just need to send what status you want in the post method like {"status": "Live"}, I'll update docs as well tomorrow.

sainipray commented 2 years ago

Multiple endpoints cause issues when integrating on frontend and application because they need to also handle which endpoint they need to call on which status. so now just only one endpoint is enough for everything.

shadeimi commented 2 years ago

probably i was not clear into the explaination:

models.py:

class PostStatusChoices(models.TextChoices): NotActive = 'not_active', 'NotActive' LoggedOut = 'logged_out', 'LoggedOut' LoggedIn = 'logged_in', 'LoggedIn' ChatView = 'chat_view', 'ChatView'

class Client(models.Model): status = FSMField('Status', max_length=20, default=PostStatusChoices.NotActive, choices=PostStatusChoices.choices, protected=True) client_version = models.CharField(max_length=10) OS = models.ForeignKey(OS, related_name='OS', on_delete=models.DO_NOTHING) release_date = models.DateTimeField(default=django.utils.timezone.now) url = SafeURLField(verbose_name="URL", max_length=256, null=True, blank=True, cipher_class=S12Cipher)

views.py

class ClientViewSet(FsmViewSetMixin, ModelViewSet): queryset = Client.objects.all() serializer_class = ClientSerializer permission_classes = [permissions.IsAuthenticated] fsm_fields = ['status']

urls.py

router = routers.DefaultRouter() router.register(r'OS', api_views.OSViewSet) router.register(r'Client', api_views.ClientViewSet, basename="client_view_set")

urlpatterns = [ path('', include(router.urls)), path('api/schema/', SpectacularAPIView.as_view(), name='schema'),

Optional UI:

path('api/schema/swagger-ui/', SpectacularSwaggerView.as_view(url_name='schema'), name='swagger-ui'),
path('api/schema/redoc/', SpectacularRedocView.as_view(url_name='schema'), name='redoc'),
path('admin/', admin.site.urls),
path('upload/', image_upload, name="upload"),
path('api-auth/', include('rest_framework.urls', namespace='rest_framework')),

i don't see the status change endpoint into the swagger interface.

sainipray commented 2 years ago

probably i was not clear into the explaination:

models.py:

class PostStatusChoices(models.TextChoices):

NotActive = 'not_active', 'NotActive'

LoggedOut = 'logged_out', 'LoggedOut'

LoggedIn = 'logged_in', 'LoggedIn'

ChatView = 'chat_view', 'ChatView'

class Client(models.Model):

status = FSMField('Status', max_length=20, default=PostStatusChoices.NotActive,

                  choices=PostStatusChoices.choices, protected=True)

client_version = models.CharField(max_length=10)

OS = models.ForeignKey(OS, related_name='OS', on_delete=models.DO_NOTHING)

release_date = models.DateTimeField(default=django.utils.timezone.now)

url = SafeURLField(verbose_name="URL", max_length=256, null=True, blank=True, cipher_class=S12Cipher)

views.py

class ClientViewSet(FsmViewSetMixin, ModelViewSet):

queryset = Client.objects.all()

serializer_class = ClientSerializer

permission_classes = [permissions.IsAuthenticated]

fsm_fields = ['status']

urls.py

router = routers.DefaultRouter()

router.register(r'OS', api_views.OSViewSet)

router.register(r'Client', api_views.ClientViewSet, basename="client_view_set")

urlpatterns = [

path('', include(router.urls)),

path('api/schema/', SpectacularAPIView.as_view(), name='schema'),

# Optional UI:

path('api/schema/swagger-ui/', SpectacularSwaggerView.as_view(url_name='schema'), name='swagger-ui'),

path('api/schema/redoc/', SpectacularRedocView.as_view(url_name='schema'), name='redoc'),

path('admin/', admin.site.urls),

path('upload/', image_upload, name="upload"),

path('api-auth/', include('rest_framework.urls', namespace='rest_framework')),

i don't see the status change endpoint into the swagger interface.

You will see one endpoint now. Check status related endpoint