se recontruye models

develop/backend
Francisco Sandoval 2023-11-12 21:37:03 -03:00
parent 4c2d63fc2e
commit 282c9a76ef
1 changed files with 56 additions and 65 deletions

View File

@ -30,7 +30,7 @@ class Comuna(models.Model):
class Conductor(models.Model): class Conductor(models.Model):
patente = models.ForeignKey('Vehiculo', models.DO_NOTHING, db_column='patente', blank=True, null=True) patente = models.OneToOneField('Vehiculo', models.DO_NOTHING, db_column='patente', primary_key=True)
rut = models.ForeignKey('Persona', models.DO_NOTHING, db_column='rut', blank=True, null=True) rut = models.ForeignKey('Persona', models.DO_NOTHING, db_column='rut', blank=True, null=True)
vigente = models.BooleanField(blank=True, null=True) vigente = models.BooleanField(blank=True, null=True)
@ -51,7 +51,7 @@ class Dispositivo(models.Model):
class Funcionario(models.Model): class Funcionario(models.Model):
rut = models.ForeignKey('Persona', models.DO_NOTHING, db_column='rut', blank=True, null=True) rut = models.OneToOneField('Persona', models.DO_NOTHING, db_column='rut', primary_key=True)
id_operador = models.ForeignKey('Operador', models.DO_NOTHING, db_column='id_operador', blank=True, null=True) id_operador = models.ForeignKey('Operador', models.DO_NOTHING, db_column='id_operador', blank=True, null=True)
desde = models.DateField(blank=True, null=True) desde = models.DateField(blank=True, null=True)
hasta = models.DateField(blank=True, null=True) hasta = models.DateField(blank=True, null=True)
@ -61,34 +61,6 @@ class Funcionario(models.Model):
db_table = 'funcionario' db_table = 'funcionario'
class GtfsCalendar(models.Model):
service_id = models.CharField(primary_key=True, max_length=150)
monday = models.BooleanField(blank=True, null=True)
tuesday = models.BooleanField(blank=True, null=True)
wednesday = models.BooleanField(blank=True, null=True)
thursday = models.BooleanField(blank=True, null=True)
friday = models.BooleanField(blank=True, null=True)
saturday = models.BooleanField(blank=True, null=True)
sunday = models.BooleanField(blank=True, null=True)
start_date = models.DateField(blank=True, null=True)
end_date = models.DateField(blank=True, null=True)
class Meta:
managed = False
db_table = 'gtfs_calendar'
class GtfsCalendarDates(models.Model):
service_id = models.DecimalField(primary_key=True, max_digits=8, decimal_places=0) # The composite primary key (service_id, date) found, that is not supported. The first column is selected.
date = models.CharField(max_length=10)
exception_type = models.DecimalField(max_digits=2, decimal_places=0, blank=True, null=True)
class Meta:
managed = False
db_table = 'gtfs_calendar_dates'
unique_together = (('service_id', 'date'),)
class GtfsFrequencie(models.Model): class GtfsFrequencie(models.Model):
id_trip = models.ForeignKey('GtfsTrips', models.DO_NOTHING, db_column='id_trip', blank=True, null=True) id_trip = models.ForeignKey('GtfsTrips', models.DO_NOTHING, db_column='id_trip', blank=True, null=True)
start_time = models.TimeField(blank=True, null=True) start_time = models.TimeField(blank=True, null=True)
@ -101,6 +73,30 @@ class GtfsFrequencie(models.Model):
db_table = 'gtfs_frequencie' db_table = 'gtfs_frequencie'
class GtfsPosiciones(models.Model):
id = models.UUIDField(primary_key=True)
trip_id = models.UUIDField()
route_id = models.IntegerField()
direction_id = models.SmallIntegerField(blank=True, null=True)
start_time = models.TimeField(blank=True, null=True)
start_date = models.DateField(blank=True, null=True)
schedule_relationship = models.SmallIntegerField(blank=True, null=True)
vehicle_license_plate = models.CharField(max_length=10, blank=True, null=True)
latitude = models.FloatField(blank=True, null=True)
longitude = models.FloatField(blank=True, null=True)
bearing = models.IntegerField(blank=True, null=True)
odometer = models.IntegerField(blank=True, null=True)
speed = models.FloatField(blank=True, null=True)
stop_sequence = models.IntegerField(blank=True, null=True)
stop_id = models.IntegerField(blank=True, null=True)
arrival_time = models.BigIntegerField(blank=True, null=True)
hora_llegada = models.DateTimeField(blank=True, null=True)
class Meta:
managed = False
db_table = 'gtfs_posiciones'
class GtfsRouteType(models.Model): class GtfsRouteType(models.Model):
id_route_type = models.DecimalField(primary_key=True, max_digits=2, decimal_places=0) id_route_type = models.DecimalField(primary_key=True, max_digits=2, decimal_places=0)
descripcion = models.CharField(max_length=100, blank=True, null=True) descripcion = models.CharField(max_length=100, blank=True, null=True)
@ -127,9 +123,14 @@ class GtfsShape(models.Model):
class GtfsStopTimes(models.Model): class GtfsStopTimes(models.Model):
id_paradero = models.OneToOneField('Paradero', models.DO_NOTHING, db_column='id_paradero', primary_key=True) # The composite primary key (id_paradero, id_trip) found, that is not supported. The first column is selected. id_paradero = models.OneToOneField('Paradero', models.DO_NOTHING, db_column='id_paradero', primary_key=True) # The composite primary key (id_paradero, id_trip) found, that is not supported. The first column is selected.
id_trip = models.ForeignKey('GtfsTrips', models.DO_NOTHING, db_column='id_trip') id_trip = models.ForeignKey('GtfsTrips', models.DO_NOTHING, db_column='id_trip')
arrival_time = models.TimeField(blank=True, null=True) arrival_time = models.CharField(max_length=15, blank=True, null=True)
stop_sequence = models.IntegerField(blank=True, null=True) stop_sequence = models.IntegerField(blank=True, null=True)
stop_headsign = models.CharField(max_length=100, blank=True, null=True) stop_headsign = models.CharField(max_length=100, blank=True, null=True)
departure_time = models.CharField(max_length=15, blank=True, null=True)
drop_off_type = models.IntegerField(blank=True, null=True)
shape_dist_traveled = models.FloatField(blank=True, null=True)
timepoint = models.IntegerField(blank=True, null=True)
pickup_type = models.IntegerField(blank=True, null=True)
class Meta: class Meta:
managed = False managed = False
@ -145,7 +146,7 @@ class GtfsTrips(models.Model):
trip_headsign = models.CharField(max_length=100, blank=True, null=True) trip_headsign = models.CharField(max_length=100, blank=True, null=True)
trip_short_name = models.CharField(max_length=100, blank=True, null=True) trip_short_name = models.CharField(max_length=100, blank=True, null=True)
direction_id = models.IntegerField(blank=True, null=True) direction_id = models.IntegerField(blank=True, null=True)
service_id = models.DecimalField(max_digits=8, decimal_places=0, blank=True, null=True, db_comment='de calendario') service_id = models.CharField(max_length=50, blank=True, null=True, db_comment='de calendario')
block_id = models.CharField(max_length=50, blank=True, null=True) block_id = models.CharField(max_length=50, blank=True, null=True)
class Meta: class Meta:
@ -154,15 +155,15 @@ class GtfsTrips(models.Model):
class LetreroLUR(models.Model): class LetreroLUR(models.Model):
codigo = models.CharField(max_length=10, primary_key=True) codigo = models.CharField(primary_key=True, max_length=10)
linea1 = models.CharField(max_length=50, blank=False, null=False) linea1 = models.CharField(max_length=50)
linea2 = models.CharField(max_length=50) linea2 = models.CharField(max_length=50, blank=True, null=True)
linea3 = models.CharField(max_length=50) linea3 = models.CharField(max_length=50, blank=True, null=True)
linea4 = models.CharField(max_length=50) linea4 = models.CharField(max_length=50, blank=True, null=True)
bgcolor1 = models.CharField(max_length=20) bgcolor1 = models.CharField(max_length=20, blank=True, null=True)
color1 = models.CharField(max_length=20) color1 = models.CharField(max_length=20, blank=True, null=True)
bgcolor2 = models.CharField(max_length=20) bgcolor2 = models.CharField(max_length=20, blank=True, null=True)
color2 = models.CharField(max_length=20) color2 = models.CharField(max_length=20, blank=True, null=True)
class Meta: class Meta:
managed = False managed = False
@ -170,7 +171,7 @@ class LetreroLUR(models.Model):
class Linea(models.Model): class Linea(models.Model):
id_linea = models.CharField(max_length=150, primary_key=True, unique=True) id_linea = models.CharField(primary_key=True, max_length=150)
id_operador = models.ForeignKey('Operador', models.DO_NOTHING, db_column='id_operador', blank=True, null=True) id_operador = models.ForeignKey('Operador', models.DO_NOTHING, db_column='id_operador', blank=True, null=True)
route_short_name = models.CharField(max_length=150, blank=True, null=True) route_short_name = models.CharField(max_length=150, blank=True, null=True)
route_desc = models.CharField(max_length=150, blank=True, null=True) route_desc = models.CharField(max_length=150, blank=True, null=True)
@ -184,6 +185,7 @@ class Linea(models.Model):
managed = False managed = False
db_table = 'linea' db_table = 'linea'
class LineaParadero(models.Model): class LineaParadero(models.Model):
id_linea_paradero = models.AutoField(primary_key=True) id_linea_paradero = models.AutoField(primary_key=True)
id_linea = models.ForeignKey(Linea, models.DO_NOTHING, db_column='id_linea') id_linea = models.ForeignKey(Linea, models.DO_NOTHING, db_column='id_linea')
@ -193,6 +195,7 @@ class LineaParadero(models.Model):
managed = False managed = False
db_table = 'linea_paradero' db_table = 'linea_paradero'
class Operador(models.Model): class Operador(models.Model):
id_operador = models.CharField(primary_key=True, max_length=150) id_operador = models.CharField(primary_key=True, max_length=150)
id_region = models.ForeignKey('Region', models.DO_NOTHING, db_column='id_region', blank=True, null=True) id_region = models.ForeignKey('Region', models.DO_NOTHING, db_column='id_region', blank=True, null=True)
@ -210,7 +213,7 @@ class Operador(models.Model):
class Paradero(models.Model): class Paradero(models.Model):
id_paradero = models.IntegerField(primary_key=True) id_paradero = models.CharField(primary_key=True, max_length=50)
id_comuna = models.ForeignKey(Comuna, models.DO_NOTHING, db_column='id_comuna', blank=True, null=True) id_comuna = models.ForeignKey(Comuna, models.DO_NOTHING, db_column='id_comuna', blank=True, null=True)
id_tipo_paradero = models.ForeignKey('TipoParadero', models.DO_NOTHING, db_column='id_tipo_paradero', blank=True, null=True) id_tipo_paradero = models.ForeignKey('TipoParadero', models.DO_NOTHING, db_column='id_tipo_paradero', blank=True, null=True)
vigente = models.BooleanField(blank=True, null=True) vigente = models.BooleanField(blank=True, null=True)
@ -233,9 +236,9 @@ class Paradero(models.Model):
class ParaderoImagen(models.Model): class ParaderoImagen(models.Model):
id_paradero_imagen = models.AutoField(primary_key=True) id_paradero_imagen = models.AutoField(primary_key=True)
id_paradero = models.ForeignKey(Paradero, models.DO_NOTHING, db_column='id_paradero', blank=False, null=False) id_paradero = models.ForeignKey(Paradero, models.DO_NOTHING, db_column='id_paradero')
imagen = models.BinaryField(blank=False, null=False) imagen = models.BinaryField(blank=True, null=True)
content_type = models.CharField(max_length=50, blank=False, null=False) content_type = models.CharField(max_length=50, blank=True, null=True)
class Meta: class Meta:
managed = False managed = False
@ -288,10 +291,10 @@ class Rol(models.Model):
class RolAplicacion(models.Model): class RolAplicacion(models.Model):
id_rol_app = models.AutoField(primary_key=True) id_aplicacion = models.ForeignKey(Aplicacion, models.DO_NOTHING, db_column='id_aplicacion')
id_aplicacion = models.ForeignKey(Aplicacion, models.DO_NOTHING, db_column='id_aplicacion') # The composite primary key (id_aplicacion, id_rol) found, that is not supported. The first column is selected.
id_rol = models.ForeignKey(Rol, models.DO_NOTHING, db_column='id_rol') id_rol = models.ForeignKey(Rol, models.DO_NOTHING, db_column='id_rol')
solo_visualizar = models.BooleanField(blank=True, null=True) solo_visualizar = models.BooleanField(blank=True, null=True)
id_rol_app = models.AutoField(primary_key=True)
class Meta: class Meta:
managed = False managed = False
@ -313,7 +316,7 @@ class SpatialRefSys(models.Model):
class TipoDispositivo(models.Model): class TipoDispositivo(models.Model):
id_dispositivo = models.ForeignKey(Dispositivo, models.DO_NOTHING, db_column='id_dispositivo', blank=True, null=True) id_dispositivo = models.ForeignKey(Dispositivo, models.DO_NOTHING, db_column='id_dispositivo', blank=True, null=True)
id_tipo_dispositivo = models.IntegerField(blank=True, null=True) id_tipo_dispositivo = models.IntegerField(primary_key=True)
class Meta: class Meta:
managed = False managed = False
@ -367,19 +370,6 @@ class Usuario(models.Model):
managed = False managed = False
db_table = 'usuario' db_table = 'usuario'
def save(self, *args, **kwargs):
# validacion se realiza solo si se esta creando el registro
if self._state.adding:
condition = models.Q(login=self.login) | models.Q(rut=self.rut)
usuario = Usuario.objects.filter(condition).first()
if usuario:
if usuario.login == self.login:
raise Exception(f"Usuario [{self.login}] ya existe!")
else:
raise Exception(f"Usuario con RUT [{self.rut}] ya existe!")
super().save(*args, **kwargs)
class UsuarioClave(models.Model): class UsuarioClave(models.Model):
login = models.OneToOneField(Usuario, models.DO_NOTHING, db_column='login', primary_key=True) login = models.OneToOneField(Usuario, models.DO_NOTHING, db_column='login', primary_key=True)
@ -414,10 +404,11 @@ class Vehiculo(models.Model):
class VehiculoLinea(models.Model): class VehiculoLinea(models.Model):
patente = models.ForeignKey(Vehiculo, models.DO_NOTHING, db_column='patente', blank=True, null=True) patente = models.OneToOneField(Vehiculo, models.DO_NOTHING, db_column='patente', primary_key=True) # The composite primary key (patente, id_linea) found, that is not supported. The first column is selected.
id_linea = models.CharField(max_length=150, blank=True, null=True) id_linea = models.ForeignKey(Linea, models.DO_NOTHING, db_column='id_linea')
vigente = models.BooleanField(blank=True, null=True) vigente = models.BooleanField(blank=True, null=True)
class Meta: class Meta:
managed = False managed = False
db_table = 'vehiculo_linea' db_table = 'vehiculo_linea'
unique_together = (('patente', 'id_linea'),)