Re: Models relationship
On Thu, 23 Aug 2012 05:20:38 -0700 (PDT), Fernando Andreacci
<fandreacci@gmail.com> declaimed the following in
gmane.comp.python.django.user:
> Hello,
>
> I'm a new Django user, and I have the following question:
>
> I have one Model called *factory, *with several fields like (name, address,
> phone, etc).
>
> Each factory can be a customer, a supplier or both.
I presume a "factory" can be a customer of more than one other
"factory"s, same for "supplier" -- otherwise you're defining a self-link
back to the same table.
Instead you are probably looking at one many-to-many table in which
both sides of the relationship are the same table. You probably need to
implement business logic to ensure that customer<>supplier.
In pseudo-SQL, this would be something like:
create table Factories
(
ID integer autoincrement primary key,
name varchar(?) not null,
address1 varchar(?) not null,
address2 varchar(?) null,
city varchar(?) not null,
state varchar(?) not null,
postcode char(10),
phone char(10)
)
create table Supplies
(
ID integer autoincrement primary key,
Supplier integer not null foreign key Factories(ID) on delete
cascade,
Customer integer not null foreign key Factories(ID) on delete
cascade
)
In Django -- Supplies would probably be an explicit "through" table;
or just managed separately.
--
Wulfraed Dennis Lee Bieber AF6VN
wlfraed@ix.netcom.com HTTP://wlfraed.home.netcom.com/
--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home