2023-06-24 13:35:17 -04:00
|
|
|
from rest_framework import serializers
|
2023-07-10 18:44:42 -04:00
|
|
|
from django.forms.models import model_to_dict
|
2023-07-12 18:25:08 -04:00
|
|
|
from django.core.serializers import serialize
|
|
|
|
|
2023-07-10 18:44:42 -04:00
|
|
|
from . import models
|
2023-06-24 13:35:17 -04:00
|
|
|
|
|
|
|
class AplicacionSerializer(serializers.ModelSerializer):
|
|
|
|
class Meta:
|
2023-07-10 18:44:42 -04:00
|
|
|
model = models.Aplicacion
|
|
|
|
fields = '__all__'
|
|
|
|
|
|
|
|
class TipoDispositivoSerializer(serializers.ModelSerializer):
|
|
|
|
class Meta:
|
|
|
|
model = models.TipoDispositivo
|
|
|
|
fields = '__all__'
|
|
|
|
|
|
|
|
class TipoParaderoSerializer(serializers.ModelSerializer):
|
|
|
|
class Meta:
|
|
|
|
model = models.TipoParadero
|
|
|
|
fields = '__all__'
|
|
|
|
|
|
|
|
class TipoTransporteSerializer(serializers.ModelSerializer):
|
|
|
|
class Meta:
|
|
|
|
model = models.TipoTransporte
|
|
|
|
fields = '__all__'
|
|
|
|
|
|
|
|
class TipoVehiculoSerializer(serializers.ModelSerializer):
|
|
|
|
class Meta:
|
|
|
|
model = models.TipoVehiculo
|
|
|
|
fields = '__all__'
|
|
|
|
|
|
|
|
class TipoTratamientoPersonaSerializer(serializers.ModelSerializer):
|
|
|
|
class Meta:
|
|
|
|
model = models.TipoTratamientoPersona
|
2023-06-25 22:41:07 -04:00
|
|
|
fields = '__all__'
|
|
|
|
|
|
|
|
class PersonaSerializer(serializers.ModelSerializer):
|
|
|
|
class Meta:
|
2023-07-10 18:44:42 -04:00
|
|
|
model = models.Persona
|
2023-06-25 22:41:07 -04:00
|
|
|
fields = '__all__'
|
|
|
|
|
2023-07-12 21:55:58 -04:00
|
|
|
class ComunaSerializer(serializers.ModelSerializer):
|
|
|
|
class Meta:
|
|
|
|
model = models.Comuna
|
|
|
|
fields = '__all__'
|
|
|
|
|
|
|
|
class RegionSerializer(serializers.ModelSerializer):
|
|
|
|
class Meta:
|
|
|
|
model = models.Region
|
|
|
|
fields = '__all__'
|
|
|
|
|
2023-08-07 20:31:09 -04:00
|
|
|
class ParaderoSerializer(serializers.ModelSerializer):
|
|
|
|
class Meta:
|
|
|
|
model = models.Paradero
|
|
|
|
fields = '__all__'
|
|
|
|
|
2023-08-27 11:08:46 -04:00
|
|
|
class OperadorSerializer(serializers.ModelSerializer):
|
|
|
|
class Meta:
|
|
|
|
model = models.Operador
|
|
|
|
fields = '__all__'
|
|
|
|
|
2023-08-15 22:22:38 -04:00
|
|
|
class LineaSerializer(serializers.ModelSerializer):
|
|
|
|
class Meta:
|
|
|
|
model = models.Linea
|
|
|
|
fields = '__all__'
|
|
|
|
|
2023-06-25 22:41:07 -04:00
|
|
|
class UsuarioSerializer(serializers.ModelSerializer):
|
2023-07-12 18:25:08 -04:00
|
|
|
# muestro informacion de persona en un objeto aparte
|
|
|
|
persona = serializers.SerializerMethodField()
|
|
|
|
|
2023-06-25 22:41:07 -04:00
|
|
|
class Meta:
|
2023-07-10 18:44:42 -04:00
|
|
|
model = models.Usuario
|
|
|
|
fields = '__all__'
|
|
|
|
read_only_fields = ['login']
|
|
|
|
|
2023-07-12 18:25:08 -04:00
|
|
|
def get_persona(self, row):
|
|
|
|
return model_to_dict(row.rut)
|
2023-07-10 18:44:42 -04:00
|
|
|
|
|
|
|
def to_representation(self, instance):
|
|
|
|
representation = super().to_representation(instance)
|
|
|
|
|
|
|
|
# Elimina el campo que deseas después de la actualización
|
|
|
|
if 'clave' in representation:
|
|
|
|
del representation['clave']
|
|
|
|
|
|
|
|
return representation
|
2023-06-25 22:41:07 -04:00
|
|
|
|
2023-06-26 16:52:08 -04:00
|
|
|
class AuthSerializer(serializers.Serializer):
|
|
|
|
username = serializers.CharField(required=True)
|
|
|
|
password = serializers.CharField(required=True, style={'input_type':'password'})
|