Jun Ren
2018-10-06 22:35:22 UTC
Hello, I defined a model as following, and writ a view based on the ModelViewset, also overidden the get_query function, as folloing:
class MachineStatus(models.Model):
Soft_ID = models.CharField(max_length=20)
operator_jun = models.CharField(max_length=20)
end_date = models.DateTimeField('date expired')
start_date = models.DateTimeField('date registeres')
machine_code = models.CharField(max_length=35)
class MachineStatusViewSetNew(viewsets.ModelViewSet):
serializer_class = MachineStatusSerializer
pagination_class = MachineStatusSetPagination
def get_queryset(self):
machine_code = self.request.data["mac_code"]
if machine_code:
queryset = MachineStatus.objects.all().filter(machine_code=machine_code)
return queryset
Question:
How to write the url for this view?
I tried following:
router.register(r'machine_status_query/(?P<mac_code>\d+)$', views.MachineStatusViewSetNew, base_name="xxx")
And typed the url "http://0.0.0.0:8000/Appauth/machinestatusviewset/machine_status_query/60" ?
it doesnot work for me? How to make it work? Any help is appreciated.
Page not found (404)
Request Method: GET
Request URL: http://0.0.0.0:8000/Appauth/machinestatusviewset/machine_status_query/60
class MachineStatus(models.Model):
Soft_ID = models.CharField(max_length=20)
operator_jun = models.CharField(max_length=20)
end_date = models.DateTimeField('date expired')
start_date = models.DateTimeField('date registeres')
machine_code = models.CharField(max_length=35)
class MachineStatusViewSetNew(viewsets.ModelViewSet):
serializer_class = MachineStatusSerializer
pagination_class = MachineStatusSetPagination
def get_queryset(self):
machine_code = self.request.data["mac_code"]
if machine_code:
queryset = MachineStatus.objects.all().filter(machine_code=machine_code)
return queryset
Question:
How to write the url for this view?
I tried following:
router.register(r'machine_status_query/(?P<mac_code>\d+)$', views.MachineStatusViewSetNew, base_name="xxx")
And typed the url "http://0.0.0.0:8000/Appauth/machinestatusviewset/machine_status_query/60" ?
it doesnot work for me? How to make it work? Any help is appreciated.
Page not found (404)
Request Method: GET
Request URL: http://0.0.0.0:8000/Appauth/machinestatusviewset/machine_status_query/60
--
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+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
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+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.