Ingen beskrivning

serializers.py 1.2KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  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. 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 = Curso
  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