print the urlpatterns and check what are all the urls router is registering for TotalViewSet. If you dont see an url for update, my guess is viewsets.ViewSet doesn't automatically catch the update function as its not the method of ViewSet. In this case you are trying to override update method. and if you want your router to register the url for update, you should use ModelViewSet instead of ViewSet.
On Wednesday, October 14, 2020 at 9:24:57 AM UTC+5:30 ashutosh...@gmail.com wrote: > can anyone see my code through teamviewer ? > > > On Monday, October 12, 2020 at 11:34:54 PM UTC+5:30 matemat...@gmail.com > wrote: > >> On Mon, Oct 12, 2020 at 6:52 AM Ashutosh Mishra <ashutosh...@gmail.com> >> wrote: >> >>> I have create update api in django,but i am not getting its api link in >>> postman >> >> >> Not sure what is the "api link" you are referring to, is it the link you >> expect to get in the "api summary" or is it a link you expect to get in the >> response of the view? >> If the second, you should include it in the serializer or directly in the >> view response - you are only returning "success" and maybe "message" in >> your view >> >> >>> urls.py >>> from rest_framework.routers import DefaultRouter >>> from doctor import views >>> from .views import* >>> router=DefaultRouter() >>> router.register(r'Patient', views.PatViewSet, basename='PatViewSet') >>> router.register(r'Sch', views.TotalViewSet, basename='TotalViewSet') >>> router.register(r'Doctor', views.DocViewSet, basename='DocViewSet') >>> >>> urlpatterns = router.urls >>> >>> views.py >>> class TotalViewSet(viewsets.ViewSet): >>> def update(self,request,pk=None): >>> try: >>> data=request.data >>> doctor=Doctor.objects.get(pk=pk) >>> print(doctor) >>> timings=data.get('schedule') >>> DAYS=Schedule.DAYS >>> for day in DAYS: >>> sch=Schedule() >>> sch.doctor=doctor >>> sch.days=day[0] >>> sch.start_time=timings[day[1]]['start_time'] >>> sch.end_time=timings[day[1]]['end_time'] >>> sch.save() >>> return Response({"success": True}, status=status.HTTP_200_OK) >>> except Exception as error: >>> #traceback.print_exc() >>> return Response({"message": str(error), "success": False}, >>> status=status.HTTP_200_OK) >>> >>> -- >>> You received this message because you are subscribed to the Google >>> Groups "Django REST framework" group. >>> To unsubscribe from this group and stop receiving emails from it, send >>> an email to django-rest-fram...@googlegroups.com. >>> To view this discussion on the web visit >>> https://groups.google.com/d/msgid/django-rest-framework/62644d15-e1f4-4beb-ad84-0ecaadf51109n%40googlegroups.com >>> >>> <https://groups.google.com/d/msgid/django-rest-framework/62644d15-e1f4-4beb-ad84-0ecaadf51109n%40googlegroups.com?utm_medium=email&utm_source=footer> >>> . >>> >> -- You received this message because you are subscribed to the Google Groups "Django REST framework" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-rest-framework+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/django-rest-framework/5263ef9d-5ec2-4a37-9758-2ae723011712n%40googlegroups.com.