Doubt with Models in Django

1

Hello, I have the following models:

class Cotizacion(TimeStampedModel):
    codigo = models.CharField(primary_key=True, max_length=12)
    proveedor = models.ForeignKey(Proveedor)
    fecha = models.DateField()
    observaciones = models.TextField()
    estado = models.BooleanField(default=True)

class OrdenCompra(TimeStampedModel):
    codigo = models.CharField(primary_key=True, max_length=12)
    cotizacion = models.ForeignKey(Cotizacion, null=True)
    fecha = models.DateField()
    total = models.DecimalField(max_digits=15, decimal_places=5)
    observaciones = models.TextField()
    estado = models.BooleanField(default=True)

With the possibility of creating a purchase order without having a quote, so I'm thinking of adding the "supplier" field to the OrderCompra Model, my question is this: Is it right to do that or is there any another way to work it? Since in case there is a quote, in order to access the provider, I simply use the quote provider and otherwise I would have to save my supplier directly in the purchase order.

That brings me to another similar problem, this time with the details of each:

class DetalleCotizacion(TimeStampedModel):
    nro_detalle = models.IntegerField()
    cotizacion = models.ForeignKey(Cotizacion)
    producto = models.ForeignKey(Producto)
    cantidad = models.DecimalField(max_digits=15, decimal_places=5)
    estado = models.BooleanField(default=True)

class DetalleOrdenCompra(TimeStampedModel):
    nro_detalle = models.IntegerField()
    orden = models.ForeignKey(OrdenCompra)
    detalle_cotizacion = models.ForeignKey(DetalleCotizacion, null=True)
    cantidad = models.DecimalField(max_digits=15, decimal_places=5)
    precio = models.DecimalField(max_digits=15, decimal_places=5)
    estado = models.BooleanField(default=True)

With the same previous possibility of creating the detail of the purchase order directly without having a quote detail by adding the "product" field to the DetailOrderPurchase model.

Greetings.

    
asked by inkarri 01.07.2016 в 23:11
source

1 answer

0

In the first situation you can place the provider in both models. In the second case the field detalle_cotizacion in DetalleOrdenCompra is not necessary since you could access it from the order: myorden.cotizacion__detallecotizacion_set.all()

    
answered by 09.11.2016 в 02:51