Jim Fritchman wrote:
> The key being the list of order items in the Order class?

Hi Jim,

I think the closest equivalent would be:

from django.db.models import *

class Order(Model):
    class Meta:
        db_table = 'orders'


class Product(Model):
    pass

class OrderItem(Model):
    quantity = IntegerField(null=False)
    price = FloatField(max_digits=10, decimal_places=2, null=False)
    total = FloatField(max_digits=10, decimal_places=2, null=False)
    order = ForeignKey(Order)
    product = ForeignKey(Product)

Now you said the key is the list of items in the Order class.  The
reason you don't see anything in there mentioning OrderItem is because
Django will add that attribute for you, calling it Order.orderitem_set.
 You would use it like so:

>>> o = Order()
>>> o.save()
>>> p = Product()
>>> p.save()
>>> OrderItem(quantity=10, price=1.5, total=2, order=o, product=p).save()
>>> OrderItem(quantity=5, price=10.5, total=20, order=o, product=p).save()

Here's the part you want:

>>> o.orderitem_set.all()
[<OrderItem: OrderItem object>, <OrderItem: OrderItem object>]

Hope that helps.

--
Brian Beck
Adventurer of the First Order


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