1
私はギャラリーAPIの詳細ビューに複数の画像を表示する必要が
が、私はでMultipleObjectsReturnedで/ API /レンタル/ギャラリー/ 1/
MultipleObjectsReturnedを示すエラーを取得しています/ API /レンタル/ギャラリー/ 1/
get()は複数のギャラリーを返しました - それは2を返しました! SHOUモデルフィールド -
views.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'
serializers.py
class GalleryListSerializer(ModelSerializer):
class Meta:
model = Gallery
class GalleryDetailSerializer(ModelSerializer):
# image = SerializerMethodField(many=True)
class Meta:
model = Gallery
fields = ('id', 'image', 'rental_id')
エラーが示すように、2つのギャラリーオブジェクトはrental_id = 1です。 –
モデルを追加してください。 – trinchet