I have a django model with a unicode FileField which I serialize with django rest framework and the FileField values get converted to ascii or some other encoding which does not contain many of the characters from the filename.
All the other fields that contain Unicode characters remain the same, only the file field gets converted. I haven't seen anything about this from the docs or from stack overflow.
I have tried specifying explicitly the encoding of the serializer like: # -- coding: utf-8 -- #, but nothing changed. Do I need to declare the field on its own in the serializer with the correct encoding? If so, then how?
Here is the serializer:
class UploadModelSerializer(serializers.ModelSerializer):
class Meta:
model = models.DatauploadUploadmodel
fields = '__all__'
Here is the model:
class DatauploadUploadmodel(models.Model):
table = models.CharField(max_length=50)
file = models.FileField(upload_to='upload_files/', max_length=200 )
user_id = models.IntegerField()
is_new_table = models.BooleanField(blank=True, null=True)
skiprows = models.IntegerField(blank=True, null=True)
status_description = models.CharField(
max_length=100, default="Feldolgozásra vár", blank=True, null=True)
status = models.CharField(max_length=100, blank=True, null=True)
upload_timestamp = models.DateTimeField()
mode = models.TextField()
class Meta:
managed = False
db_table = 'dataupload_uploadmodel'
This is the view:
class UploadmodelList(generics.ListCreateAPIView):
queryset = models.DatauploadUploadmodel.objects.all()
serializer_class = serializers.UploadModelSerializer
permission_classes = [AuthorAllUser]
This is how the filename looks like in the api:
k%C3%B6lts%C3%A9gek-2022-09-091.xlsx
And this is how it looks like in the database:
költségek-2022-09-09.xlsx