On 8/13/07, Amirouche <[EMAIL PROTECTED]> wrote:
> What do you mean, I can't understand.

OK, suppose you are running an online store, so you have a database
table "orders", which lists orders customers have placed, and another
"addresses" which lists the addresses to ship the orders to. To
calculate the shipping cost for an order, you need the total amount of
the order and the address it ships to; calculating it with an
application which does pure raw SQL looks like this:

query = "SELECT orders.amount, addresses.address FROM orders INNER
JOIN addresses ON addresses.id = orders.address_id WHERE orders.id =
%s"
cursor.execute(query, [23])
row = cursor.fetchall()[0]
shipping_amount = calculate_shipping(amount=row[0], address=row[1])

Doing it with an ORM looks like this:

order = Order.objects.get(id=23)
shipping_amount = order.calculate_shipping()

The fact that the ORM automatically gives you instances of
domain-specific classes means that you immediately have access to your
customized business logic, and that you can encapsulate it in those
classes and rely on their availability, which improves the design of
your code. It also significantly cuts down the amount of code you need
to write, and makes it clearer what's going on: you're calculating the
shipping price of Order #23.


-- 
"Bureaucrat Conrad, you are technically correct -- the best kind of correct."

--~--~---------~--~----~------------~-------~--~----~
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