On 10/5/05, Yesh <[EMAIL PROTECTED]> wrote:
> Here is a sample schema
> Invoice (number, date, debtor, address)
> InvoiceItems (product, qty, unitPrice, value, InvoiceKey)
First off, at least skim the docs on SQLObject and Kid. You will need
at least a basic grasp on them.
Your model.py should have classes that look like something like this
(you could get fancier with debtor and address, but this is a start):
class Invoice(SQLObject):
_connection = hub
number = StringCol(alternateId=True, unique=True, notNull=True)
date = DateTimeCol(notNull=True)
debtor = StringCol()
address = StringCol()
items = MultipleJoin('InvoiceItem')
class InvoiceItem(SQLObject):
_connection = hub
product = StringCol()
quantity = IntCol()
unitPrice = CurrencyCol()
invoice = ForeignKey('Invoice')
def _get_value(self):
return self.quantity * self.unitPrice
>
> What should the Kid template look like and what must the
> save method do to automatically commit this to database.
Assuming you provide an invoice object as "invoice" from your
controller, this will do:
<table>
<tr>
<td align="right">Invoice Number</td>
<td>${invoice.number}</td>
</tr>
[continue with the rest of the invoice data, except for items]
</table>
<table>
<tr>
<th>Product</th>
<th>Quantity</th>
<th>Unit Price</th>
<th>Total</th>
</tr>
<tr py:for="item in invoice.items">
<td>${item.product}</td>
<td>${item.quantity}</td>
<td>${item.unitPrice}</td>
<td>${item.value}</td>
</tr>
</table>
Updating items is covered in the "wiki in 20 minutes" demo.
--
Tim Lesher <[EMAIL PROTECTED]>