Skip to content

Commit

Permalink
added validations
Browse files Browse the repository at this point in the history
  • Loading branch information
Pranshu1902 committed Aug 2, 2023
1 parent 19b63d2 commit 4d63686
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion care/facility/api/serializers/hospital_doctor.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from rest_framework import serializers

from rest_framework.exceptions import ValidationError
from care.facility.api.serializers import TIMESTAMP_FIELDS
from care.facility.models import DOCTOR_TYPES, HospitalDoctors
from config.serializers import ChoiceField
Expand All @@ -16,3 +16,9 @@ class Meta:
"area_text",
)
exclude = TIMESTAMP_FIELDS + ("facility", "external_id")

def validate(self, attrs):
# validate that the doctor count is positive
if attrs["count"] < 0:
raise ValidationError("Doctor count cannot be negative")
return super().validate(attrs)

0 comments on commit 4d63686

Please sign in to comment.