Re: Foreignkeys on multiple fields
Forget Django for the moment, and study "database normalization".
Then consider that Django, so far as I know, adds a primary key
field to each table (model). The main purpose of integer primary key
fields IS to be used as the target of foreign key lookups.
I understand this (at least the basics). I do not particularly like that django introduces the limitation of having a single primary key variable when the database backend does not have such a limitation. I was thinking that I could have django have its integer primary key, but do foreignkey lookups on different variables. I now understand that I was wrong in doing so.
Tables don't "inherit" from other tables; they "join" to records in
other tables where the record is specified by some singular key. In SQL
terms:
select people.person-name, address.village, address.household
from people
left join address
on people.addressID = address.ID
This is indeed right. But I would like my second table to have two variables, Village and HouseholdNumber, whose values it directly gets from the first table. I know that I could obtain these through a select query as you have illustrated above. But what I am trying to do is that,when I fill data in an inline formset connected to second table, the table should automatically get these two variables based on the relationship you have used in the query above.
I am sorry for being inaccurate and verbose in my expression, and am grateful for your patience with my ignorance.
Vikas
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home