I'm implementing a small e-shop application in django. My question concerns modelling an Order with many OrderLines: How to model the Order to OrderLines relationship with the OrderLines accessible directly from the Order, i.e.
Order
def addOrderLine
def allOrderLines
I want to access the OrderLines from the Order and not have to get them from the db directly. Django offers the possibility to define ForeignKeys, but this doesn't solve my problem, because I'd have to define the following:
class OrderLine(models.Model):
order = models.ForeignKey(Order)
With this definition I'd have to fetch the OrderLines directly from the db and not through the Order.
I'm might use this definition and provide methods on the Order
level. This, however, doesn't work because if I define the Order
above the OrderLine
in the models.py
file, the Order
doesn't see the OrderLines