The error I am getting is
ImproperlyConfigured at /usercombo/
Could not resolve URL for hyperlinked relationship using view name "usercombo-detail". You may have failed to include the related model in your API, or incorrectly configured the `lookup_field` attribute on this field.
In my view.py
class UserComboViewSet(viewsets.ModelViewSet):
"""
API endpoint that allows UserCombo to be viewed or edited.
"""
queryset = UserCombo.objects.all()
serializer_class = UserComboSerializer
permission_classes = (IsAuthenticated,EmailConfirmationPermission)
lookup_field='customURL'
def get_queryset(self):
return UserCombo.objects.filter(user=self.request.user)
In my serializer.py:
class UserCombo(serializers.HyperlinkedModelSerializer):
customURL = serializers.CharField(
required=False,)
data = JSONSerializerField()
class Meta:
model = UserCombo
unique_together = (("product", "user"),)
fields = ('url', 'user', 'product', 'data', 'customURL', 'is_active')
lookup_field ='customURL'
If I remove the two lookup_field lines everything works fine, but the lookup_field for the usercombo object is the pk.
It looks like using lookup_field was removed as an option for ModelSerializer.Meta in django-rest-framework version 3.2. This error is because of this removal. It should still be possible to use lookup_field with extra_kwargs.
http://www.django-rest-framework.org/topics/3.2-announcement/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With