我想用join product_ratings table获取所有产品表值。我做了这样的事情,但是这段代码给了我AttributeError ...
产品序列化程序中的product_ratings = ProductRatingSerializer(many = True),并在字段中使用了此值,但它不起作用:
其完整的错误消息:
Got AttributeError when attempting to get a value for field `product_ratings` on serializer `ProductSerializer`.
The serializer field might be named incorrectly and not match any attribute or key on the `Product` instance.
Original exception text was: 'Product' object has no attribute 'product_ratings'.
Run Code Online (Sandbox Code Playgroud)
查看:
class StoreApiView(mixins.CreateModelMixin, generics.ListAPIView):
lookup_field = 'pk'
serializer_class = ProductSerializer
def get_queryset(self):
qs = Product.objects.all()
query = self.request.GET.get('q')
if query is not None:
qs = qs.filter(
Q(title__icontains=query) | …Run Code Online (Sandbox Code Playgroud)