@ Mudassar .Thanx for your reply but this query is not working.
On Thursday, September 1, 2016 at 8:58:53 PM UTC+5, M Hashmi wrote:
-- On Thursday, September 1, 2016 at 8:58:53 PM UTC+5, M Hashmi wrote:
What did you get with:products = Product.objects.filter(account=user) As it is inheriting user from get_shopaccount method.Regards,MudassarOn Thu, Sep 1, 2016 at 8:45 AM, Shamaila Moazzam <shamaila...@gmail.com> wrote:am making a shops dashboard view .in that view i have used a mixin as mentioned below....my issue is i want to get products related to a specific account or user . i have products m2m in shop model and also have user f.k in Shop model. In get_shopproducts() function in ShopAccountMixin()..i am unable to filter products of a requested account..... please reply... shops/models.py--class Shop(models.Model): user = models.ForeignKey(settings.AUT
H_USER_MODEL ) product = models.ManyToManyField(Product) ...... def __unicode__(self): return str(self.user.username) products/models.py class Product(models.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, ... def __unicode__(self): #def __str__(self): return self.title shops/mixins.py class ShopAccountMixin(LoginRequiredMixin , object): def get_shopaccount(self): user = self.request.user shopaccount = Shop.objects.filter(user=user) if shopaccount.exists(): return shopaccount else: return None def get_shopproducts(self): account = self.get_shopaccount() ## this is the problem area.. here i want to filter like products = Product.objects.all(account....???)??? return products class shopsDashBoard(ShopAccountMixin , FormMixin, View): model = Shop form_class = SellerForm template_name = "shops/seller.html" def get(self, request, *args, **kwargs): apply_form = self.get_form() account = self.get_shopaccount() exists = account active = None context = {} if exists: active = account.active context["active"] = active if not exists and not active: context["title"] = "Apply for Account" context["apply_form"] = apply_form elif exists and not active: context["title"] = "Account Pending" elif exists and active: context["title"] = "Shops Dashboard" #products = Product.objects.filter(seller=account) context["products"] = self.get_shopproducts() return render(request, "shops/dashboard.html", context)
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...@googlegroups.com .
To post to this group, send email to django...@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/ .CAFimi6wB1Ycnz2On4EALzvM5b0M- a17sB4PXpKFA5KdCiFK4WQ%40mail. gmail.com
For more options, visit https://groups.google.com/d/optout .
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+unsubscribe@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/128fd036-6cdb-4031-b268-a420411f0b3e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
No comments:
Post a Comment