Hi all,
I have php web programming background, and new to Django. I am helping my brother to build an online system to manage inventory, and I've got a database design & coding problem recently. Needing help!
That is, I have a set of tables of "possible products", "inventory", "suppiler", etc. I want to attach a "comment" to each of them. Therefore, I think I should make a generic "comment" table to hold all the comments of products, inventory, suppiler.
--
possible_products
id: int (pk)
name: varchar
url: varchar
price: decimal
created_at: datetime
updated_at: datetime
--
comments
id: int (pk)
parent_id: int (fk)
content: text
author: int (fk)
table: char (which the table this comment belongs to)
created_at: datetime
updated_at: datatime
--
My problem is, when "possible_products" table is the parent of "comment", then a foreign key of the parent (id number) is stored in the "comment" table in order to link up them.
However, how about the fk of the "inventory" table and the "suppiler" table? It should not be that: I create 2 more columns of "inventory_id" nor "suppiler_id" in "comments" table. (That is, I should not create the 4th column when I want to link up the 4th parent table.)
So, Should I use generic forgien key of Django? (so that, my "comment" table design is right.) And how to use/implement it?
P.S I mainly develop the system in the Admin section of Django.
Regards,
Aaron Law Ho hon
--~--~---------~--~----~------------~-------~--~----~
Free as in Freedom ;-)
--~--~---------~--~----~------------~-------~--~----~