DJANGO complex modelling

Posted by SledgehammerPL on Stack Overflow See other posts from Stack Overflow or by SledgehammerPL
Published on 2010-05-31T09:01:38Z Indexed on 2010/05/31 9:02 UTC
Read the original article Hit count: 199

Filed under:
|

Hello.

I have such model now: receipt contains components. component contain product.

The difference between component and product is, that component has quantity and measure unit: eg. component is 100g sugar - sugar is a product.

So I need to make lots of components to satisfy different recipes - 100g sugar is not equal 200g sugar

I wonder if I can remodel it to kick off components - in pure sql it's rather easy, but I'm trying to USE django - not making workarounds.

class Receipt(models.Model): name = models.CharField(max_length=128) (...) components = models.ManyToManyField(Component)

class Component(models.Model): quantity = models.FloatField(max_length=9) unit = models.ForeignKey(Unit) product = models.ForeignKey(Product)

class Product(models.Model): name = models.CharField(max_length = 128)

TIA

© Stack Overflow or respective owner

Related posts about django

Related posts about modelling