Serialization
Serialization
Model -> Serializer -> View -> URL -> Project URL
Basic config
class ClientSerializer(serializers.ModelSerializer):
# practitioners = PractitionerSerializer(many=True, read_only=True)
class Meta:
= Client
model = '__all__' fields
Adding Custom Fields
class PractitionerSerializer(serializers.ModelSerializer):
= serializers.PrimaryKeyRelatedField(many=True, read_only=True, source='clients')
client_ids
class Meta:
= Practitioner
model = '__all__' fields
Adding Relations Fields
class QuestionnaireSerializer(serializers.ModelSerializer):
= QuestionSerializer(many=True, read_only=True)
questions
class Meta:
= Questionnaire
model = '__all__' fields