gpt4 book ai didi

python - Haystack - 'SearchQuerySet' 对象没有属性 'model'

转载 作者:太空宇宙 更新时间:2023-11-03 16:41:29 25 4
gpt4 key购买 nike

我正在尝试序列化 haystack 结果,

api.py

class PinSearchViewSet(viewsets.ReadOnlyModelViewSet):
http_method_names = ['get']
queryset = Pin.objects.all()
serializer_class = PinSearchSerializer

def get_queryset(self, *args, **kwargs):
request = self.request
queryset = EmptySearchQuerySet()
if request.GET.get('q') is not None:
query = request.GET.get('q')
queryset = SearchQuerySet().filter(content=query)
return queryset

序列化器.py

class PinSearchSerializer(serializers.ModelSerializer):
class Meta:
model = Pin
fields = ('id', 'office_name', 'pin_code', 'office_type', 'delivery_status',
'division_name', 'region_name', 'circle_name', 'taluk', 'district', 'state')

但我收到以下错误,

'SearchQuerySet' object has no attribute 'model'

最佳答案

序列化程序期望pin对象,但您返回SearchResut对象

试试这个

class PinSearchViewSet(viewsets.ReadOnlyModelViewSet):
http_method_names = ['get']
queryset = Pin.objects.all()
serializer_class = PinSearchSerializer

def get_queryset(self, *args, **kwargs):
request = self.request
queryset = EmptySearchQuerySet()
if request.GET.get('q') is not None:
query = request.GET.get('q')
queryset = SearchQuerySet().filter(content=query).models(Pin)
return [i.object for i in queryset]

我还在searchQuerySet中指定了pin模型

关于python - Haystack - 'SearchQuerySet' 对象没有属性 'model',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36748842/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com