That's exactly what I needed. Thank you *very* much! On Mon, Sep 3, 2012 at 8:44 PM, Dennis Lee Bieber <wlfr...@ix.netcom.com>wrote:
> On Mon, 3 Sep 2012 18:51:45 -0700 (PDT), Barry Morrison > <bdmorri...@gmail.com> declaimed the following in > gmane.comp.python.django.user: > > > Model: http://dpaste.org/dqwmc/ > > > > There can be many products. > > Okay, a table of products... > > > There can be many distributors. > > and a table of distributors > > > A product could have none or more distributors. > > Normal intersect table behavior > > > A distributor could only distribute a single product once. > > This clause is unclear... > > > A distributor could distribute all products. > > > > This clause is irrelevant -- it doesn't restrict the data (vs if > you > had some requirement that a distributor carrying products a..m is not > allowed to carry product n) > > > I imagine a form (admin side): > > > > Product Name: > > Product Description: > > Product Image: > > > > Distributor 1: Radio Field/Boolean > > Distributor 2: Radio Field/Boolean > > Etc. etc. > > > > For some reason I can't wrap my head around this. > > Your model (per the linked web page) current ties a product > instance > to ONE DISTRIBUTOR ONLY. > > In pseudo-SQL, you have defined > > create table Distributor > ( > ID integer autoincrement primary key, #django adds this > Name varchar(255) not null, #it is redundant to preface fields > > #with "distributor" when they are > > #IN the table Distributor > URL varchar(255) null, #URL type is django > operation > Product boolean #this field is meaningless as > > #there is no product referenced > > #here > ); > > create table Product > ( > ID integer autoincrement primary key, > Name varchar(255) not null, > Description blob, #or some such large text field > Image varchar(255) null, #image type is django usage > Distributor integer foreign key references Distributor (ID), > #this basically says that this product can have > #only ONE distributor > ); > > What you really need is not a one-to-many link (one distributor can > have many products, but each product can only have one distributor) but > a many-to-many linkage. > > create table Distributor > ( > ID integer autoincrement primary key, #django adds this > Name varchar(255) not null, > URL varchar(255) null, > ); > > create table Product > ( > ID integer autoincrement primary key, > Name varchar(255) not null, > Description blob, #or some such large text field > Image varchar(255) null, #image type is django usage > ); > > create table ProductDistribution > ( > ID integer autoincrement primary key, > ProductID integer foreign key references Product(ID), > DistributorID integer foreign key references Distributor(I), > unique (ProductID, DistributorID) > ); > > As I understand it, Django will create the equivalent of > ProductDistribution when you declare a many-to-many relationship in one > of the parent tables. > > -- > Wulfraed Dennis Lee Bieber AF6VN > wlfr...@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+unsubscr...@googlegroups.com. > For more options, visit this group at > http://groups.google.com/group/django-users?hl=en. > > -- 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+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.