Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

no methods for status change #1

Open
shadeimi opened this issue Aug 22, 2022 · 4 comments
Open

no methods for status change #1

shadeimi opened this issue Aug 22, 2022 · 4 comments

Comments

@shadeimi
Copy link

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
Copy link
Owner

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
Copy link
Owner

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
Copy link
Author

shadeimi commented Aug 22, 2022

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
Copy link
Owner

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants