Recurso aninhado configurado incorretamente usando o HyperlinkedModelSerializer

Eu escolhi oFramework REST do Django eroteadores aninhados drf construir uma API paraProdutos eProductReports. Aqui estão as classes relevantes:

# models.py
from django.db import models


class Product(models.Model):
    created_at = models.DateTimeField(auto_now_add=True)


class ProductReport(models.Model):
    user_name = models.CharField(max_length=256, blank=False)
    created_at = models.DateTimeField(auto_now_add=True)
    product = models.ForeignKey('Product', default=1)

...

# serializers.py
from rest_framework import serializers
from models import Product, ProductReport


class ProductSerializer(serializers.HyperlinkedModelSerializer):

    class Meta:
        model = Product


class ProductReportSerializer(serializers.HyperlinkedModelSerializer):

    product = ProductSerializer()

    class Meta:
        model = ProductReport

...

# views.py
from django.shortcuts import render
from rest_framework import viewsets, mixins
from rest_framework.response import Response
from models import Product, ProductReport
from serializers import ProductSerializer, ProductReportSerializer


class ProductViewSet(mixins.RetrieveModelMixin,
                   mixins.ListModelMixin,
                   viewsets.GenericViewSet):
    queryset = Product.objects.all()
    serializer_class = ProductSerializer


class ProductReportViewSet(viewsets.ViewSet):
    queryset = ProductReport.objects.all()
    serializer_class = ProductReportSerializer

    def list(self, request, product_pk=None):
        queryset = self.queryset.filter(product=product_pk)
        serializer = ProductReportSerializer(queryset, many=True, context={'request': request})
        return Response(serializer.data)

    def retrieve(self, request, pk=None, product_pk=None):
        queryset = self.queryset.get(pk=pk, product=product_pk)
        serializer = ProductReportSerializer(queryset)
        return Response(serializer.data)

...

# urls.py
from django.conf.urls import patterns, include, url
from django.contrib import admin
from rest_framework import routers
from rest_framework_nested.routers import SimpleRouter, NestedSimpleRouter
from productreports import views

router = routers.SimpleRouter()
router.register(r'products', views.ProductViewSet)

products_router = NestedSimpleRouter(router, r'products', lookup='product')
products_router.register(r'productreports', views.ProductReportViewSet)


urlpatterns = patterns('',
    url(r'^', include(router.urls)),
    url(r'^', include(products_router.urls)),
    url(r'^admin/', include(admin.site.urls)),
    url(r'^api-auth/', include('rest_framework.urls', namespace='rest_framework')),
)

Quando eu visitohttp://localhost:8000/products/1/productreports/ Os seguinteserro é mostrado:

Configuração inadequada em / products / 1 / productreports /
Não foi possível resolver o URL para o relacionamento com hiperlink usando o nome da exibição "productreport-detail". Você pode ter falhado em incluir o modelo relacionado em sua API ou configurado incorretamente olookup_field atributo neste campo.

Há algumas coisas que não tenho certeza se estão configuradas corretamente:

product = models.ForeignKey('Product', default=1)many=True noserializer = ProductReportSerializer(queryset, many=True, context={'request': request}) ...cada produto pode termuitos relatórios de produtosoProductReportSerializer em gerallookup='product' noproducts_router = NestedSimpleRouter(router, r'products', lookup='product')Atualizar

Notei que o erro ocorre apenas quando hápelo menos um associadorelatório de produção paraprodutos. Se orelatórios de produção tabela não contém nenhuma entrada para um determinadoprodutos então a resposta da API está correta.

Quando inspeciono oserializer noProductReportViewSet#list Eu recebo:

ProductReportSerializer([
    <ProductReport: ProductReport object>, <ProductReport: ProductReport object>, 
    <ProductReport: ProductReport object>, <ProductReport: ProductReport object>, 
    <ProductReport: ProductReport object>, <ProductReport: ProductReport object>, 

'...(remaining elements truncated)...'], context={'request': <rest_framework.request.Request object>}, many=True):
        url = HyperlinkedIdentityField(view_name='productreport-detail')
        product = ProductSerializer():
            url = HyperlinkedIdentityField(view_name='product-detail')
            created_at = DateTimeField(read_only=True)
        user_name = CharField(max_length=256)
        created_at = DateTimeField(read_only=True)

questionAnswers(0)

yourAnswerToTheQuestion