class Shop(models.Model):
user = models.ForeignKey(settings.AUTH_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+unsubscribe@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.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
def get_shopproducts(self):
account = self.get_shopaccount()
## this is the problem area..
here i want to filter like
products = Product.objects.filter(pk__in=[id for i.product in
account ])
return products
I hope this help you.
--
You received this message because you are subscribed to a topic in the Google Groups "Django users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/django-users/8zbsj_yUmlY/unsubscribe.
To unsubscribe from this group and all its topics, send an email to django-users+unsubscribe@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/7496fc3e-e583-446f-b2de-6ef9ddcd888b%40googlegroups.com.