I need to obtain the price of the type to which the vehicles belong in order to add them and register them in the Rental Model
class Tipo(models.Model):
descripcion = models.CharField(max_length=100)
precio = models.DecimalField(max_digits=20,decimal_places=2,default=Decimal('0.00'))
km_mantenimiento = models.DecimalField(max_digits=20,decimal_places=2,default=Decimal('0.00'))
def __str__(self):
return self.descripcion
class Vehiculo(models.Model):
placa = models.CharField(primary_key=True,max_length=100)
descripcion = models.CharField(max_length=100)
marca = models.CharField(max_length=100)
modelo = models.CharField(max_length=100)
cilindrada = models.CharField(max_length=100)
tipo = models.ForeignKey(Tipo)
km_recorrido = models.DecimalField(max_digits=20,decimal_places=2,default=Decimal('0.00'))
activo = models.BooleanField(default=True)
def __str__(self):
return self.descripcion
class Alquiler(models.Model):
fecha = models.DateTimeField(auto_now_add = timezone.now())
hora_inicio = models.TimeField()
hora_fin = models.TimeField()
cajero = models.ForeignKey(User)
cliente = models.ForeignKey(Cliente)
vehiculos = models.ManyToManyField(Vehiculo)
#total = models.DecimalField(max_digits=20, decimal_places=2, default=Decimal('0.00'))
class Meta:
permissions = (
("add_alquileres", "Puede crear Alquileres"),
)
def __int__(self):
return self.cliente
def motos(self):
return ', '.join([Vehiculo.descripcion for Vehiculo in self.vehiculos.all()])