So I created models: http://dpaste.org/D4r7L/ forms: http://dpaste.org/KMShj/ the output of the form generates: http://dpaste.org/ua41K/
The form creates text areas to enter distributor name/url. What I'd like on this form is a set of radio buttons to allow a true/false if the product is distributed by a specific distributor. Do I need to create another field on the Distributor model and set a boolean field/widget? Thanks, Barry On Monday, September 3, 2012 8:45:07 PM UTC-7, Dennis Lee Bieber wrote: > > On Mon, 3 Sep 2012 18:51:45 -0700 (PDT), Barry Morrison > <bdmor...@gmail.com <javascript:>> 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 > wlf...@ix.netcom.com <javascript:> > HTTP://wlfraed.home.netcom.com/ > > -- You received this message because you are subscribed to the Google Groups "Django users" group. To view this discussion on the web visit https://groups.google.com/d/msg/django-users/-/g6qoFbbFggIJ. 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.