Django Rest do not show postgresql binary field in

2019-09-17 21:46发布

i have model called "Person" and i want to store profile pictures in database in postgres i use "bytea" type for storing images and in my django model i use "BinaryField"

My model is like this:

class Person(models.Model)
    name = models.TextField(blank=True, null=True)
    photo = models.BinaryField(blank=True, null=True)

My Django serializer:

class PersonSerializer(modelserializer):
    class Meta:
        models = Person
        Fields= '__all__'

And finaly my view :

class PersonView(ModelViewSet):
    queryset= Person.objects.all()
    serializer_class = PersonSerializer

my problem is that when i want to insert data django do not show "photo" field in the view what is my mistake??

1条回答
beautiful°
2楼-- · 2019-09-17 22:36

BinaryField are not supported by Django REST framework. You'll need to write a serializer field class and declare it in a mapping to make this work.

查看更多
登录 后发表回答