I've been working on a Purchase Order app but I'm getting a little confused 
how I'm going to put it all together.

I have 3 models -

class PurchaseOrder(models.Model):
    po_number = models.IntegerField(default=get_po_number, unique=True)
    po_date = models.DateField()
    invoice_number = models.ForeignKey(Invoice, on_delete=models.CASCADE)
    ....


class PurchaseOrderItem(models.Model):
    po_number_fk = models.ForeignKey(PurchaseOrder, 
on_delete=models.CASCADE)
    qty = models.IntegerField()
    unit = models.CharField(max_length=100, blank=True, null=True)
    description = models.CharField(max_length=255)
    unit_price = models.DecimalField(max_digits=6, decimal_places=2)
    amount = models.DecimalField(max_digits=6, decimal_places=2)


class PurchaseOrderTotal(models.Model):
    po_number_fk = models.ForeignKey(PurchaseOrder, 
on_delete=models.CASCADE)
    subtotal = models.DecimalField(max_digits=6, decimal_places=2)
    tax = models.DecimalField(max_digits=6, decimal_places=2, 
default="7.82")
    shipping = models.DecimalField(max_digits=6, decimal_places=2)
    other = models.DecimalField(max_digits=6, decimal_places=2)
    total = models.DecimalField(max_digits=6, decimal_places=2)


the first (PurchaseOrder) holds information about the purchase order 
itself. ie. what the invoice number is, the vendor, etc.
the second (PurchaseOrderItem) lists items in the purchase order to purchase
the third (PurchaseOrderTotal) totals up the amounts from the items and 
adds tax etc. (I may not need this model.. I can probably put this info in 
the first model?)


Does it look like I'm going about this in the right way or should I take 
away the third model and put those fields from the third model into the 
first model? How do I total up all prices for all items? I'm sure I'll need 
to do some sort of loop to total up all prices but where do I do that? In 
the form_valid fucntion? or do I override the save function and do it 
there? Thanks!

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/dc6a1cb9-0770-49d9-9c89-92d1f947e718%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to