On Jul 2, 8:26 am, NC <naveenchandr...@gmail.com> wrote: > I am trying to create a customer database app and the model is as > follows.. > > # Create your models here. > > class Customer(models.Model): > name = models.CharField(max_length=40) > address = models.CharField(max_length=100) > city = models.CharField(max_length=20) > state = models.CharField(max_length=20) > country = models.CharField(max_length=20) > phone = models.CharField(max_length=15) > mobile = models.CharField(max_length=15) > fax = models.CharField(max_length=15) > email = models.EmailField(max_length=15) > website = models.URLField() > remarks = models.CharField(max_length=100) > > class Product(models.Model): > productname = models.CharField(max_length=20) > invoiceno = models.CharField(max_length=10) > serialno = models.CharField(max_length=20) > make = models.CharField(max_length=20) > model = models.CharField(max_length=20) > capacity = models.CharField(max_length=20) > installeddate = models.DateField() > remark = models.CharField(max_length=25) > > I am confused on how to relate this. > One customer can buy multiple products so this has to be a one to many > relation. [Correct me if I am wrong] > should I include " customer = models.ForeignKey(Customer)" in the > "product" class or product = models.ManytomanyField(Product) in the > "customer" class?
I would imagine it is a ManyToMany relationship, because even though a customer can buy many products, you don't want to have to define a separate Product each time a customer buys one. Actually, this might be better with an intermediate table - eg Order. An order would link a single customer (foreign key) to multiple products (many to many). -- DR. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---