I have a model whose Primary Key is a TextField. This is a minimalistic reproduction of my issue:
Model:
class Filename(models.Model):
path = models.TextField(primary_key=True)
Serializer:
class FilenameSerializer(ModelSerializer):
class Meta:
model = Filename
fields = '__all__'
View:
class FilenameViewSet(ModelViewSet):
queryset = Filename.objects.all()
serializer_class = FilenameSerializer
I'm using a DefaultRouter
for URLs. Here is the problem: If I sent
{"path":"test"}
with a POST /filename/
I can perfectly retrieve my object with GET /filename/test/
as you would expect. However, if I POST /filename/
something like {"path":"c:\\test"}
I would expect either GET /filename/c%3A%5Ctest/
or GET /filename/c%3A%5C%5Ctest/
to be the proper way to get it, but none of those works. Does anybody knows what's going on?
Update: The webserver logs show Not Found: /filename/c:\test
so it's being decoded properly at some moment. Maybe some URL regex issue?