I don't know how much you are into Django, but in case you didn't you really need to ready carefully the following articles from the docs.
- Working with forms <https://docs.djangoproject.com/en/1.10/topics/forms/> - Creating forms from models <https://docs.djangoproject.com/en/1.10/topics/forms/modelforms/#module-django.forms.models> - The Django admin site <https://docs.djangoproject.com/en/1.10/ref/contrib/admin/#module-django.contrib.admin> there is more but this is just to get started. now after this, you should understand that in order to achieve what you want, you could do something like this: class ProductAdmin(admin.ModelAdmin): #... exclude = ('shop_user',) def save_model(self, request, obj, form, change): if not change: #set user on create only obj.shop_user = request.user obj.save() On Wednesday, August 17, 2016 at 8:11:23 PM UTC+3, Shamaila Moazzam wrote: > > shops/admin.py > > from .models import Shop > > admin.site.register(Shop) > > > > products/admin.py > > > from .models import Product, Variation, ProductImage, Category, > ProductFeatured, color_product, size_product > > > > class ProductImageInline(admin.TabularInline): > model = ProductImage > extra = 0 > max_num = 10 > > class VariationInline(admin.TabularInline): > model = Variation > extra = 0 > max_num = 10 > > > class ProductAdmin(admin.ModelAdmin): > list_display = ['__unicode__', 'price',] > inlines = [ > ProductImageInline, > VariationInline, > > > ] > class Meta: > model = Product > > > admin.site.register(Product, ProductAdmin) > > > > > #admin.site.register(Variation) > > admin.site.register(ProductImage) > > > admin.site.register(Category) > > > admin.site.register(ProductFeatured) > > admin.site.register(color_product) > > admin.site.register(size_product) > > > > Thanks for reply Todor, But how to fix it in admin.py? > > On Wednesday, August 17, 2016 at 6:37:51 PM UTC+5, Shamaila Moazzam wrote: >> >> I am trying to create a parent model for my products app and I need to >> provide the user reference. I've registered the Shop model with admin.py. >> Now I have problem that when I see in model it shows all the products >> listed before. I only intend to show products added by the shop owner. Also >> I need to register shop using built-in auth system so how do I do that, >> should I add user field in Shop or in Product. To brief in detail following >> are my models. Thanks for your kind help and apologies if as beginner i've >> missed any information or if the question isn't up to standard. >> >> shops/models.py: >> >> class Shop(models.Model): >> #shop_user = models.ForeignKey(settings.USER_AUTH_MODEL, >> blank=False, null=False) >> product = models.ManyToManyField(Product, related_name='myshop',null= >> False, blank=True) >> 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) >> >> >> products/models.py: >> >> 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',) >> >> >> def __unicode__(self): #def __str__(self): >> return self.title >> >> >> -- 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/269459ce-f0bf-4850-8fad-c91f30f181a9%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.