我需要在GalleryAPI的详细视图中显示多个图像,但我收到一个错误声明
多个对象返回/api/rentals/gallery/1/
get()返回了多个库--它返回了2!
视图.py
class GalleryListAPIView(ListAPIView):
# queryset = Rental.objects.all()
serializer_class = GalleryListSerializer
pagination_class = RentalPageNumberPagination
def get_queryset(self, *args, **kwargs):
queryset_list = Gallery.objects.all()
return queryset_list
class GalleryDetailAPIView(RetrieveAPIView):
queryset = Gallery.objects.all()
serializer_class = GalleryDetailSerializer
lookup_field = 'rental_id'
序列化程序.py
^{pr2}$
看看documentation
因为您使用了}。而且,可能有两个gallery对象与
rental_id
,并且使用的是url/api/rentals/gallery/1/
,这里的1
是rental_id
,而不是图库的{rental_id=1
相关,这就是为什么在结果中得到这些对象。在相关问题 更多 >
编程相关推荐