I'm trying to create a simple invoice application where an Invoice has
(0..n) LineItems.

I've created form that contains a few entries for line items, and using
the standard AddManipulator I'm able to save a new invoice and its line
items to the database.

But I would like to add some code that performs a few calculations
before the new objects are saved to the database:

1. for each LineItem, compute extended = quantity * unit_price

2. Invoice.subtotal = sum(LineItem.extended)

3. Invoice.taxAmount = sum(LineItem.extended if LineItem.isTaxable) *
taxRate

4. Invoice.total = Invoice.subtotal + Invoice.taxAmount

Writing recalc methods that perform these operations on the model
objects is pretty simple, but how can I invoke such logic before the
objects are actually saved in the database?

Overriding save() in the model class doesn't work because
db.models.manipulators.AutomaticManipulator.save() creates and saves
the parent (Invoice) before creating the related children (LineItem).

Is there a method to extract a new instance of a model object from the
POST data without calling save()?


Thanks for your help,

Matthew


--~--~---------~--~----~------------~-------~--~----~
 You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to