Linked Questions

Popular Questions

What is the contain method in Dango rest_framework Filter

Asked by At

Let's say I have a database that looks like this:

{
    name: 'We love Football',
    type: 'Sports',
}
{
    name: 'Let's play Football',
    type: 'Sports'
}
{
    name: 'Let's play Basketball',
    type: 'Sports'
}

I need to implement something like this:

class GameAPIListView(ListAPIView):
     serializer_class = GameSerializer
    def get_queryset(self):
        term = self.request.GET['term']
        data = Game.objects.filter(name.contains(term))
        return data

If I type "Fooball", the first two items will be returned, since they contain the token "Football". What is the correct way to do this? Thanks in advance.

Related Questions