Django rest framework - what url should I provide for generic filters?
I am using django with a rest base and I am trying to use a generic filter. My view looks like this:
class Agents(generics.ListAPIView):
serializer_class = serializer.AgentSerializer
model = serializer_class.Meta.model
filter_backends = (filters.DjangoFilterBackend,)
queryset = models.Agent.objects.all()
filter_fields = ('available', 'online', 'agency')
and I added the following url:
url('^api/agents/$', api_views.Agents.as_view()),
now when i enter urls like these:
api/agents/?online=False
api/agents/?available=True
it works and returns correct list based on filters. however, when I try this:
api/agents/123/?online=False
I am getting page not found.
reading this document tells me that when I use a generic filter it also works to return a single object and they give the following url as an example: http://example.com/api/products/4675/?category=clothing&max_price = 10.00
but I didn't understand, should I create my own url specifically to get one object by id? or should it happen automatically? should I implement get_queryset () that take parameters from a url and return all objects or a specific object and have two urls that use the same look?
The docs are not very clear.
thank!
source to share