Fakultas Ilmu Komputer UI

Commit 8ab3e74a authored by Nabila Febri Viola's avatar Nabila Febri Viola
Browse files

[GREEN] Change acara donor serializers to match the new acara donor model and add more validations

parent d8938beb
......@@ -5,15 +5,25 @@ from acara_donor.models import AcaraDonor
class AcaraDonorSerializer(serializers.ModelSerializer):
def validate(self, data):
queryset = AcaraDonor.objects.filter(nama_institusi=data['nama_institusi'],
queryset = AcaraDonor.objects.filter(
if queryset.exists():
raise serializers.ValidationError("Acara donor darah ini sudah diajukan.")
if data['waktu_donor'] < timezone.now():
raise serializers.ValidationError("Tanggal acara donor darah tidak boleh di masa lalu.")
raise serializers.ValidationError(
"Acara donor darah ini sudah diajukan.")
if data['waktu_mulai'] < timezone.now():
raise serializers.ValidationError(
"Pelaksanaan acara donor darah tidak boleh di masa lalu.")
if data['waktu_berakhir'] < data['waktu_mulai']:
raise serializers.ValidationError(
"Jam pelaksanaan acara donor darah tidak valid.")
return data
class Meta:
model = AcaraDonor
exclude = ["user", "status"]
exclude = ["user", "nomor", "status"]
extra_kwargs = {'foto_lokasi': {'required': False}}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment