Answer the question
In order to leave comments, you need to log in
How can I dynamically get data from axios get request and use it as an argument in filter() on the django side?
What and where do I need to add so that I can dynamically get the variable from the request url and insert it as an argument in filter () when accessing the ORM, I will be happy with the links, because I could not find anything (
this is how the url axios request looks like: 127.0.0.1:8000/api/disk-brands/?page=3&brand=name-brand
serializers.py
class CatalogDisksSerializer(serializers.HyperlinkedModelSerializer):
class Meta:
model = CatalogDisks
fields = (
'id',
'brand',
'title',
)
class CatalogDiskBrandsViewSet(viewsets.ReadOnlyModelViewSet):
queryset = CatalogDisks.objects.all().filter(brand='MOMO') # и вот здесь мне нужно вместо MOMO вставить переменную,
# которую передаю в GET запросе
serializer_class = CatalogDisksSerializer
pagination_class = PaginationDisks
def get_serializer_class(self):
return CatalogDisksSerializer
Answer the question
In order to leave comments, you need to log in
Filtering against query parameters . In theory, it should work for viewsets as well.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question