Im still new with Django Rest Framework, I want to filter the queryset using an URL parameter.
Here's my models.py:
class Offre(models.Model):
title = models.CharField(max_length=100, blank=True, default=0)
secteur = models.CharField(max_length=50, null=True)
idRecruteur = models.ForeignKey(Recruteur,verbose_name = "idRecruteur", on_delete=models.CASCADE, default=None)
def __str__(self):
return "Offre: {}".format(self.title)
Here's what i did in urls.py:
router = DefaultRouter();
router.register(r'OffresByRecruteur/(?P<idRecruteur_id>\d+)/$', OffreRecruteurViewSet, base_name='inoutreports')
urlpatterns = router.urls
Finally api.py:
class OffreRecruteurViewSet(ModelViewSet):
queryset = Offre.objects.all()
serializer_class = OffreSerializer
def get_queryset(self, *args, **kwargs):
return self.queryset.filter(idRecruteur_id=self.request.GET.get('idRecruteur_id'))
This generates
Using the URLconf defined in djangular.urls, Django tried these URL patterns, in this order:
^scrumboard/ ^OffresByRecruteur/(?P<idRecruteur_id>\d+)/$/$ [name='inoutreports-list']
^scrumboard/ ^OffresByRecruteur/(?P<idRecruteur_id>\d+)/$\.(?P<format>[a-z0-9]+)/?$ [name='inoutreports-list']
^scrumboard/ ^OffresByRecruteur/(?P<idRecruteur_id>\d+)/$/(?P<idRecruteur>[^/.]+)/$ [name='inoutreports-detail']
^scrumboard/ ^OffresByRecruteur/(?P<idRecruteur_id>\d+)/$/(?P<idRecruteur>[^/.]+)\.(?P<format>[a-z0-9]+)/?$ [name='inoutreports-detail']
The current path, scrumboard/OffresByRecruteur/1/, didn't match any of these.
What am I doing wrong ?