Create UUID on client and save primary key with Django REST Framework and using a POST

前端 未结 1 352
囚心锁ツ
囚心锁ツ 2020-12-31 07:40

I\'d like to be able to create a UUID on the client and send it to Django Rest Framework (DRF) and use that for the Primary Key of the Mod

相关标签:
1条回答
  • 2020-12-31 08:26

    The id field of the serializer is set as read-only because of the editable=False argument.

    Model fields which have editable=False set, and AutoField fields will be set to read-only by default,

    Try declaring it explicitly:

    class PersonCreateSerializer(serializers.ModelSerializer):
        # Explicit declaration sets the field to be `read_only=False`
        id = serializers.UUIDField()
    
        class Meta:
            model = Person
            fields = ('id', 'username', 'email', 'password')
    
    0 讨论(0)
提交回复
热议问题