Aucune description

serializers.py 961B

123456789101112131415161718192021222324252627282930313233
  1. from .models import Facultad, Curso, Matricula
  2. from rest_framework import serializers
  3. class FacultadSerializer(serializers.ModelSerializer):
  4. class Meta:
  5. model = Facultad
  6. fields = ('__all__')
  7. def create(self, validated_data):
  8. instance, created = Facultad.objects.get_or_create(**validated_data)
  9. # print(instance, created)
  10. if(created == False):
  11. print('ya se creo')
  12. return validated_data
  13. class CursoSerializer(serializers.ModelSerializer):
  14. class Meta:
  15. model = Curso
  16. fields = ('__all__')
  17. class MatriculaSerializer(serializers.ModelSerializer):
  18. class Meta:
  19. model = Matricula
  20. fields = ('__all__')
  21. def create(self, validated_data):
  22. instance, created = Matricula.objects.get_or_create(**validated_data)
  23. # print(instance, created)
  24. if(created == False):
  25. print('ya se creo')
  26. return validated_data