D
D
Durilka962022-04-03 12:14:15
Django
Durilka96, 2022-04-03 12:14:15

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',
                )


view.py
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

1 answer(s)
A
Alexander Nesterov, 2022-04-03
@Durilka96

Filtering against query parameters . In theory, it should work for viewsets as well.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question