假设我有一个数据库,如下所示:
{
name: 'We love Football',
type: 'Sports',
}
{
name: 'Let's play Football',
type: 'Sports'
}
{
name: 'Let's play Basketball',
type: 'Sports'
}
我需要实现以下内容:
class GameAPIListView(ListAPIView):
serializer_class = GameSerializer
def get_queryset(self):
term = self.request.GET['term']
data = Game.objects.filter(name.contains(term))
return data
如果我键入“ Fooball”,则将返回前两个项目,因为它们包含令牌“ Football”。正确的方法是什么?提前致谢。