Django Rest Framework NoReverseMatch не является допустимой функцией представления или именем шаблона
Сначала некоторый контекст :
Класс моделей :
class Property(models.Model, AbstractUsagesLinked, AbstractErrorsFinder, InsurableMixin):
type = models.ForeignKey(PropertyType, verbose_name=_('type de lot'), null=True, blank=True, related_name='properties_set', on_delete=models.CASCADE)
# other fields
Класс Сериализаторы :
class PropertySerializer(serializers.HyperlinkedModelSerializer, FlexFieldsModelSerializer):
type = serializers.HyperlinkedRelatedField(view_name="api:propertytype-detail", read_only=True) # add hyperlink reference
# others fields
class Meta:
model = Property
fields = [field.name for field in model._meta.fields]
expandable_fields = {
'type': (PropertyTypeSerializer, {'many': False}),
# others fields
}
class PropertyTypeSerializer(serializers.HyperlinkedModelSerializer, FlexFieldsModelSerializer):
class Meta:
model = PropertyType
fields = [field.name for field in model._meta.fields]
Виды класса :
@permission_classes((Check_API_KEY_Auth, ))
class PropertyDetail(RetrieveAPIView):
queryset = Property.objects.all()
serializer_class = PropertySerializer
pagination_class = CustomPagination
@permission_classes((Check_API_KEY_Auth, ))
class PropertyTypeDetail(RetrieveAPIView):
queryset = PropertyType.objects.all()
serializer_class = PropertyTypeSerializer
pagination_class = CustomPagination
Урлы :
api.urls.py :
urlpatterns = [
# lots of path
path('property/', views.PropertyList.as_view(), name="property-list"),
path('property/<int:pk>/', views.PropertyDetail.as_view(), name="property-detail"),
path('propertytype/', views.PropertyTypeList.as_view(), name="propertytype-list"),
path('propertytype/<int:pk>/', views.PropertyTypeDetail.as_view(), name="propertytype-detail"),
main.urls.py :
urlpatterns = [ # lots of path
url(r'^api/', include((api.urls, 'api'), namespace='api')),
]
Когда я запрашиваю свойство, я получаю :
django.urls.exceptions.NoReverseMatch: Reverse for 'propertytype-detail' not found. 'propertytype-detail' is not a valid view function or pattern name.
django.core.exceptions.ImproperlyConfigured: Could not resolve URL for hyperlinked relationship using view name "propertytype-detail". You may have failed to include the related model in your API, or incorrectly configured the `lookup_field` attribute on this field.
Только исключения происходят на некоторых свойствах id и не на всех свойствах, я не могу найти почему.