Do you have any error with the code you posted ? It look like you already have a foreign key to your user.
2016-08-17 15:33 GMT+02:00 Shamaila Moazzam <shamaila.moaz...@gmail.com>: > Hi, > > I am a beginner and please forgive me if my question is not up to the > standard. I've got two models one is Product which is saved in db already > and another one is Shop. I am trying to related both models with following > code. > > class Product(models.Model): > user = models.ForeignKey(settings.USER_AUTH_MODEL) > title = models.CharField(max_length=120) > description = models.TextField(blank=True, null=True) > price = models.DecimalField(decimal_places=2, max_digits=20) > publish_date = models.DateTimeField(auto_now=False, auto_now_add=False, > null=True, blank= True) > expire_date = models.DateTimeField(auto_now=False, auto_now_add=False, > null=True, blank=True) > active = models.BooleanField(default=True) > categories = models.ManyToManyField('Category', blank=True) > default = models.ForeignKey('Category', related_name='default_category', > null=True, blank=True) > hitcounts = GenericRelation(HitCount, content_type_field='content_type', > object_id_field='object_pk',) > > > objects = ProductManager() > > > class Meta: > ordering = ["-title"] > > > def __unicode__(self): > return self.title > > > class Shop(models.Model): > product = models.ManyToManyField(Product) > > title = models.CharField(max_length=120, null=False) > image = models.ImageField(upload_to=image_upload_to_shop, null=True) > location = models.CharField(max_length=120) > > > > > def __unicode__(self): > return str(self.title) > > > > > With above I've got it added in my admin.py for Shop app and now I have a > problem. When I add a shop it shows all the past products prepopulated in my > "products" field. > I just need to add the products that shop account holder has uploaded. I > wish to use django\s built-in auth model to register shop holders. Again the > confusion is that where should I add > USER_AUTH_MODEL in "Shop" or in "Products". If I added it shop app then for > beginner like me it will be easy to use querysets. Please advise the best > practice for above scenario. > > -- > You received this message because you are subscribed to the Google Groups > "Django users" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to django-users+unsubscr...@googlegroups.com. > To post to this group, send email to django-users@googlegroups.com. > Visit this group at https://groups.google.com/group/django-users. > To view this discussion on the web visit > https://groups.google.com/d/msgid/django-users/bf649b76-0a5e-4e48-b54c-dfdcd0ae1a16%40googlegroups.com. > For more options, visit https://groups.google.com/d/optout. -- Cordialement, Coues Ludovic +336 148 743 42 -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at https://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAEuG%2BTaAb_nooX2bzMT_mrnRLD--keYP9SM_v7BTLj6fdw_owg%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.