I have a django model that has two different fields (phones and emails) and serializers like these:
Models:
class Phone(ValueBase):
serializers:
class PersonSerializer(serializers.ModelSerializer): prefix = typebase_serializer_factory(PersonPrefix) person_type = typebase_serializer_factory(PersonType) gender = typebase_serializer_factory(Gender) created_on = serializers.DateTimeField(read_only=True) class Meta: model = Person fields = ('id', 'prefix' ,'name', 'middlename', 'lastname', 'phones', 'emails') class PhoneSerializer(serializers.ModelSerializer):
I am trying to declare my many of many fields as HyperlinkedRelatedFields, ModelFields, but I cannot get the Person post to accept json, like this for creating:
{ "name": "TestName", "lastname": "TestLast", "prefix": 2, #pk "gender": 2, #pk "person_type": 1, #pk "register": "na", "phones": [{"value": "551199999998"}, {"value": "551199999998"}] #many to many field }
What I expect from this is the relationship of the prefix, gender, and person_type with the corresponding field of identifiers and phones to create all the array elements in the database and link to each other.
Is it possible if I do not write my own seriliazer?
source share