No Description

serializers.py 1.6KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. from .models import Facultad, Curso, Matricula, ProximoSemestre
  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. def create(self, validated_data):
  18. instance, created = Curso.objects.get_or_create(**validated_data)
  19. # print(instance, created)
  20. if(created == False):
  21. print('ya se creo')
  22. return validated_data
  23. class MatriculaSerializer(serializers.ModelSerializer):
  24. class Meta:
  25. model = Matricula
  26. fields = ('__all__')
  27. def create(self, validated_data):
  28. instance, created = Matricula.objects.get_or_create(**validated_data)
  29. # print(instance, created)
  30. if(created == False):
  31. print('ya se creo')
  32. return validated_data
  33. class ProximoSemestreSerializer(serializers.ModelSerializer):
  34. class Meta:
  35. model = ProximoSemestre
  36. fields = ('__all__')
  37. def create(self, validated_data):
  38. instance, created = ProximoSemestre.objects.get_or_create(
  39. **validated_data)
  40. # print(instance, created)
  41. if(created == False):
  42. print('ya se creo')
  43. return validated_data