Hi. I have a question about writing normalized models. I began writing
an app that has non-normalized tables, and would like to rewrite it
with a normalized design.
I have non-normalized legacy tables like this without foreign keys or
many-to-many relationships, which I would like to have.
Contract
id contract_id product_id rebate_pct
1 1 123 0.22
2 1 124 0.30
Note repeating contract_id above. Each contract may have a different
number of products associated with it
Each product in the Contract table in turn has its own rebate_pct.
Product
id product product_name quantity_per_p
product_description
1 123 name1
20 some_desc1
2 124 name2
20 some_desc2
I'd like to define the Product model such that it has the unique
contract_id per row, but each contract_id should have the associated
multiple products and their rebate percentages.
I started with:
class Contract(models.Model):
contract_id = models.IntegerField(unique=True)
product = models.ManyToManyField(Product)
but don't know about rebate_pct. Should it be a ManyToMany into a
special rebates table?
Thanks.
--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to [email protected].
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.