serializers.py 669 B

12345678910111213141516171819202122
  1. from rest_framework import serializers, status
  2. from rest_framework.exceptions import ValidationError
  3. from apps.indicator.models import Indicator
  4. from apps.indicatortype.models import IndicatorType
  5. from apps.patient.models import Patient
  6. class IndicatorSerializer(serializers.ModelSerializer):
  7. class Meta:
  8. model = Indicator
  9. fields = '__all__'
  10. extra_kwargs = {
  11. 'observing': {'required': False}
  12. }
  13. def create(self, validated_data):
  14. user = self.context['request'].user
  15. validated_data['observing'] = user
  16. indicator = Indicator(**validated_data)
  17. indicator.save()
  18. return indicator