Re: Issue in filtering .....(want to show only the products that are sold and have status of paid in orders App)

2016-09-20 Thread Shamaila Moazzam
there is no m2m relation in products and cart model

*carts/models.py*

class CartItem(models.Model):
cart = models.ForeignKey("Cart")
item = models.ForeignKey(Variation)
quantity = models.PositiveIntegerField(default=1)
line_item_total = models.DecimalField(max_digits=10, decimal_places=2)

def remove(self):
return self.item.remove_from_cart()

def __unicode__(self):
return self.item.title

class Cart(models.Model):
user = models.ForeignKey(settings.AUTH_USER_MODEL, null=True,
blank=True)
items = models.ManyToManyField(Variation, through=CartItem)
timestamp = models.DateTimeField(auto_now_add=True, auto_now=False)
updated = models.DateTimeField(auto_now_add=False, auto_now=True)
subtotal = models.DecimalField(max_digits=50, decimal_places=2,
default=0.00)
.

def __unicode__(self):
return str(self.id)

*products/models.py*

class Product(models.Model):
user = models.ForeignKey(settings.AUTH_USER_MODEL)
seller = models.ForeignKey(SellerAccount)
# shop = models.ForeignKey(Shop)
title = models.CharField(max_length=120)
description = models.TextField(blank=True, null=True)
price = models.DecimalField(decimal_places=2, max_digits=20)




class Variation(models.Model):
product = models.ForeignKey(Product)
title = models.CharField(max_length=120)
price = models.DecimalField(decimal_places=2, max_digits=20)
sale_price = models.DecimalField(decimal_places=2, max_digits=20,
null=True, blank=True)
active = models.BooleanField(default=True)
inventory = models.IntegerField(null=True, blank=True) #refer none ==
unlimited amount

def __unicode__(self):
return self.title

On Tue, Sep 20, 2016 at 11:39 AM, Asad Jibran Ahmed 
wrote:

> I'd need to see the full Cart model to confirm, but try something like
> this to get all products for Orders with the paid status:
>
> def get_products(self):
>  orders = Order.objects.filter(user=self.user, status='paid')
>  products_list = list()
>  for o in orders:
>   for p in o.cart.products:
>products_list.append(p)
>
>  return products_list
>
> This depends on their being a ManyToMany relationship to Product in the
> Cart model.
>
> Asad Jibran Ahmed 
> http://blog.asadjb.com
>
> On Tue, Sep 20, 2016 at 10:12 AM, Shamaila Moazzam <
> shamaila.moaz...@gmail.com> wrote:
>
>> user = models.ForeignKey(settings.AUTH_USER_MODEL)
>>
>> this user is a F.K in products model, orders model , carts model right.
>> cart is also a F.K in orders like this
>>
>> class Order(models.Model):
>> status = models.CharField(max_length=120,
>> choices=ORDER_STATUS_CHOICES, default='created')
>> cart = models.ForeignKey(Cart)
>> user = models.ForeignKey(UserCheckout, null=True)
>> billing_address = models.ForeignKey(UserAddress,
>> related_name='billing_address', null=True)
>> shipping_address = models.ForeignKey(UserAddress,
>> related_name='shipping_address', null=True
>> ..
>> seller = models.ForeignKey(SellerAccount, null=True)..i have
>> added this field now to relate sellers app with orders...
>>
>> now advise me
>> how to filter orders of products with status of paid .( of a logged in
>> user )
>>
>> :)
>>
>>
>>
>>
>>
>>
>>
>>
>> On Tuesday, September 20, 2016 at 10:44:19 AM UTC+5, Asad Jibran Ahmed
>> wrote:
>>>
>>> Can you share the Cart model? The Order has a foreign key to Cart. I
>>> think that may be the model holding details of the products.
>>>
>>> On Tuesday, September 20, 2016 at 9:32:12 AM UTC+4, Asad Jibran Ahmed
>>> wrote:

 How are you associating a product with an order? Is there a way to get
 a list of products sold for each order?

 Asad Jibran Ahmed 
 http://blog.asadjb.com

 On Tue, Sep 20, 2016 at 9:24 AM, Shamaila Moazzam <
 shamaila...@gmail.com> wrote:

> Thanks for you kind response ...I am stuck in it :(
>
> I have seller as a foreign key in Product model..
>
> *products/models.py*
>
> class Product(models.Model):
> user = models.ForeignKey(settings.AUTH_USER_MODEL)
> seller = models.ForeignKey(SellerAccount)
>
> title = models.CharField(max_length=120)
> description = models.TextField(blank=True, null=True)
> price = models.DecimalField(decimal_places=2, max_digits=20)
>
>
>
>
>
> On Tuesday, September 20, 2016 at 10:09:01 AM UTC+5, Asad Jibran Ahmed
> wrote:
>>
>> Hi,
>>  While you didn't show us the Product model, I assume it has a
>> ForeignKey to the Order model. To filter for Products that have an
>> Order with a sold status, you should look at the documentation for
>> filtering on relationships at https://docs.djangoproject.com
>> /en/1.10/topics/db/queries/#lookups-that-span-relationships.
>> Regards,
>> Jibran
>>
>> On Tuesday, September 20, 2016 at 

Re: Issue in filtering .....(want to show only the products that are sold and have status of paid in orders App)

2016-09-20 Thread Asad Jibran Ahmed
I'd need to see the full Cart model to confirm, but try something like this
to get all products for Orders with the paid status:

def get_products(self):
 orders = Order.objects.filter(user=self.user, status='paid')
 products_list = list()
 for o in orders:
  for p in o.cart.products:
   products_list.append(p)

 return products_list

This depends on their being a ManyToMany relationship to Product in the
Cart model.

Asad Jibran Ahmed 
http://blog.asadjb.com

On Tue, Sep 20, 2016 at 10:12 AM, Shamaila Moazzam <
shamaila.moaz...@gmail.com> wrote:

> user = models.ForeignKey(settings.AUTH_USER_MODEL)
>
> this user is a F.K in products model, orders model , carts model right.
> cart is also a F.K in orders like this
>
> class Order(models.Model):
> status = models.CharField(max_length=120,
> choices=ORDER_STATUS_CHOICES, default='created')
> cart = models.ForeignKey(Cart)
> user = models.ForeignKey(UserCheckout, null=True)
> billing_address = models.ForeignKey(UserAddress,
> related_name='billing_address', null=True)
> shipping_address = models.ForeignKey(UserAddress,
> related_name='shipping_address', null=True
> ..
> seller = models.ForeignKey(SellerAccount, null=True)..i have
> added this field now to relate sellers app with orders...
>
> now advise me
> how to filter orders of products with status of paid .( of a logged in
> user )
>
> :)
>
>
>
>
>
>
>
>
> On Tuesday, September 20, 2016 at 10:44:19 AM UTC+5, Asad Jibran Ahmed
> wrote:
>>
>> Can you share the Cart model? The Order has a foreign key to Cart. I
>> think that may be the model holding details of the products.
>>
>> On Tuesday, September 20, 2016 at 9:32:12 AM UTC+4, Asad Jibran Ahmed
>> wrote:
>>>
>>> How are you associating a product with an order? Is there a way to get a
>>> list of products sold for each order?
>>>
>>> Asad Jibran Ahmed 
>>> http://blog.asadjb.com
>>>
>>> On Tue, Sep 20, 2016 at 9:24 AM, Shamaila Moazzam >> > wrote:
>>>
 Thanks for you kind response ...I am stuck in it :(

 I have seller as a foreign key in Product model..

 *products/models.py*

 class Product(models.Model):
 user = models.ForeignKey(settings.AUTH_USER_MODEL)
 seller = models.ForeignKey(SellerAccount)

 title = models.CharField(max_length=120)
 description = models.TextField(blank=True, null=True)
 price = models.DecimalField(decimal_places=2, max_digits=20)





 On Tuesday, September 20, 2016 at 10:09:01 AM UTC+5, Asad Jibran Ahmed
 wrote:
>
> Hi,
>  While you didn't show us the Product model, I assume it has a
> ForeignKey to the Order model. To filter for Products that have an
> Order with a sold status, you should look at the documentation for
> filtering on relationships at https://docs.djangoproject.com
> /en/1.10/topics/db/queries/#lookups-that-span-relationships.
> Regards,
> Jibran
>
> On Tuesday, September 20, 2016 at 9:04:18 AM UTC+4, Shamaila Moazzam
> wrote:
>>
>> hi
>> I am a beginner in django/python * :(*
>>
>> I am making a dashboard of sellers App.
>> I am stuck in filtering orders of the products according to the
>> logged in user(seller)
>>
>> *sellers/models.py*
>>
>> from django.conf import settings
>> from django.core.urlresolvers import reverse
>> from django.db import models
>> from django.contrib.auth.models import User
>>
>>
>>
>> class SellerAccount(models.Model):
>> user = models.ForeignKey(User)
>> managers = models.ManyToManyField(settings.AUTH_USER_MODEL,
>> related_name="manager_sellers", blank=True)
>> active = models.BooleanField(default=False)
>> timestamp = models.DateTimeField(auto_now_add=True,
>> auto_now=False)
>>
>>
>> def __unicode__(self):
>> return str(self.user.username)
>>
>> def get_absolute_url(self):
>> return reverse("products:vendor_detail",
>> kwargs={"vendor_name": self.user.username})
>>
>>
>> *orders/models.py*
>>
>> class Order(models.Model):
>> status = models.CharField(max_length=120,
>> choices=ORDER_STATUS_CHOICES, default='created')
>> cart = models.ForeignKey(Cart)
>> user = models.ForeignKey(UserCheckout, null=True)
>> billing_address = models.ForeignKey(UserAddress,
>> related_name='billing_address', null=True)
>> shipping_address = models.ForeignKey(UserAddress,
>> related_name='shipping_address', null=True)
>> shipping_total_price = models.DecimalField(max_digits=50,
>> decimal_places=2, default=5.99)
>> order_total = models.DecimalField(max_digits=50,
>> decimal_places=2, )
>> order_id = models.CharField(max_length=20, null=True, blank=True)
>> paymethod = 

Re: Issue in filtering .....(want to show only the products that are sold and have status of paid in orders App)

2016-09-20 Thread Shamaila Moazzam
user = models.ForeignKey(settings.AUTH_USER_MODEL)

this user is a F.K in products model, orders model , carts model right.
cart is also a F.K in orders like this

class Order(models.Model):
status = models.CharField(max_length=120, choices=ORDER_STATUS_CHOICES, 
default='created')
cart = models.ForeignKey(Cart)
user = models.ForeignKey(UserCheckout, null=True)
billing_address = models.ForeignKey(UserAddress, 
related_name='billing_address', null=True)
shipping_address = models.ForeignKey(UserAddress, 
related_name='shipping_address', null=True
..
seller = models.ForeignKey(SellerAccount, null=True)..i have added 
this field now to relate sellers app with orders...

now advise me 
how to filter orders of products with status of paid .( of a logged in user 
)

:)








On Tuesday, September 20, 2016 at 10:44:19 AM UTC+5, Asad Jibran Ahmed 
wrote:
>
> Can you share the Cart model? The Order has a foreign key to Cart. I think 
> that may be the model holding details of the products.
>
> On Tuesday, September 20, 2016 at 9:32:12 AM UTC+4, Asad Jibran Ahmed 
> wrote:
>>
>> How are you associating a product with an order? Is there a way to get a 
>> list of products sold for each order?
>>
>> Asad Jibran Ahmed 
>> http://blog.asadjb.com
>>
>> On Tue, Sep 20, 2016 at 9:24 AM, Shamaila Moazzam > > wrote:
>>
>>> Thanks for you kind response ...I am stuck in it :(
>>>
>>> I have seller as a foreign key in Product model..
>>>
>>> *products/models.py*
>>>
>>> class Product(models.Model):
>>> user = models.ForeignKey(settings.AUTH_USER_MODEL)
>>> seller = models.ForeignKey(SellerAccount)
>>>
>>> title = models.CharField(max_length=120)
>>> description = models.TextField(blank=True, null=True)
>>> price = models.DecimalField(decimal_places=2, max_digits=20)
>>>
>>>
>>>
>>>
>>>
>>> On Tuesday, September 20, 2016 at 10:09:01 AM UTC+5, Asad Jibran Ahmed 
>>> wrote:

 Hi,
  While you didn't show us the Product model, I assume it has a 
 ForeignKey to the Order model. To filter for Products that have an 
 Order with a sold status, you should look at the documentation for 
 filtering on relationships at 
 https://docs.djangoproject.com/en/1.10/topics/db/queries/#lookups-that-span-relationships
 .
 Regards,
 Jibran

 On Tuesday, September 20, 2016 at 9:04:18 AM UTC+4, Shamaila Moazzam 
 wrote:
>
> hi
> I am a beginner in django/python * :(*
>
> I am making a dashboard of sellers App.
> I am stuck in filtering orders of the products according to the logged 
> in user(seller)
>
> *sellers/models.py*
>
> from django.conf import settings
> from django.core.urlresolvers import reverse
> from django.db import models
> from django.contrib.auth.models import User
>
>
>
> class SellerAccount(models.Model):
> user = models.ForeignKey(User)
> managers = models.ManyToManyField(settings.AUTH_USER_MODEL, 
> related_name="manager_sellers", blank=True)
> active = models.BooleanField(default=False)
> timestamp = models.DateTimeField(auto_now_add=True, auto_now=False)
>
>
> def __unicode__(self):
> return str(self.user.username)
>
> def get_absolute_url(self):
> return reverse("products:vendor_detail", 
> kwargs={"vendor_name": self.user.username})
>
>
> *orders/models.py*
>
> class Order(models.Model):
> status = models.CharField(max_length=120, 
> choices=ORDER_STATUS_CHOICES, default='created')
> cart = models.ForeignKey(Cart)
> user = models.ForeignKey(UserCheckout, null=True)
> billing_address = models.ForeignKey(UserAddress, 
> related_name='billing_address', null=True)
> shipping_address = models.ForeignKey(UserAddress, 
> related_name='shipping_address', null=True)
> shipping_total_price = models.DecimalField(max_digits=50, 
> decimal_places=2, default=5.99)   
> order_total = models.DecimalField(max_digits=50, decimal_places=2, 
> )
> order_id = models.CharField(max_length=20, null=True, blank=True)
> paymethod = models.CharField(max_length=120, choices=CHOICES, 
> default='CreditCard')
> 
>
> def __unicode__(self):
> return str(self.cart.id)
>
>
> *sellers/mixins.py*
>
>
> import datetime
>
> from django.db.models import Count, Min, Sum, Avg, Max
>
> from dress.mixins import LoginRequiredMixin
> from orders.models import Transaction, Order
> from products.models import Product
>
> from .models import SellerAccount
>
>
>
> class SellerAccountMixin(LoginRequiredMixin, object):
> account = None
> products = []
> transactions = []
> orders = []
>
> def 

Re: Issue in filtering .....(want to show only the products that are sold and have status of paid in orders App)

2016-09-19 Thread Asad Jibran Ahmed
Can you share the Cart model? The Order has a foreign key to Cart. I think 
that may be the model holding details of the products.

On Tuesday, September 20, 2016 at 9:32:12 AM UTC+4, Asad Jibran Ahmed wrote:
>
> How are you associating a product with an order? Is there a way to get a 
> list of products sold for each order?
>
> Asad Jibran Ahmed 
> http://blog.asadjb.com
>
> On Tue, Sep 20, 2016 at 9:24 AM, Shamaila Moazzam <
> shamaila.moaz...@gmail.com> wrote:
>
>> Thanks for you kind response ...I am stuck in it :(
>>
>> I have seller as a foreign key in Product model..
>>
>> *products/models.py*
>>
>> class Product(models.Model):
>> user = models.ForeignKey(settings.AUTH_USER_MODEL)
>> seller = models.ForeignKey(SellerAccount)
>>
>> title = models.CharField(max_length=120)
>> description = models.TextField(blank=True, null=True)
>> price = models.DecimalField(decimal_places=2, max_digits=20)
>>
>>
>>
>>
>>
>> On Tuesday, September 20, 2016 at 10:09:01 AM UTC+5, Asad Jibran Ahmed 
>> wrote:
>>>
>>> Hi,
>>>  While you didn't show us the Product model, I assume it has a 
>>> ForeignKey to the Order model. To filter for Products that have an Order 
>>> with a sold status, you should look at the documentation for filtering on 
>>> relationships at 
>>> https://docs.djangoproject.com/en/1.10/topics/db/queries/#lookups-that-span-relationships
>>> .
>>> Regards,
>>> Jibran
>>>
>>> On Tuesday, September 20, 2016 at 9:04:18 AM UTC+4, Shamaila Moazzam 
>>> wrote:

 hi
 I am a beginner in django/python * :(*

 I am making a dashboard of sellers App.
 I am stuck in filtering orders of the products according to the logged 
 in user(seller)

 *sellers/models.py*

 from django.conf import settings
 from django.core.urlresolvers import reverse
 from django.db import models
 from django.contrib.auth.models import User



 class SellerAccount(models.Model):
 user = models.ForeignKey(User)
 managers = models.ManyToManyField(settings.AUTH_USER_MODEL, 
 related_name="manager_sellers", blank=True)
 active = models.BooleanField(default=False)
 timestamp = models.DateTimeField(auto_now_add=True, auto_now=False)


 def __unicode__(self):
 return str(self.user.username)

 def get_absolute_url(self):
 return reverse("products:vendor_detail", kwargs={"vendor_name": 
 self.user.username})


 *orders/models.py*

 class Order(models.Model):
 status = models.CharField(max_length=120, 
 choices=ORDER_STATUS_CHOICES, default='created')
 cart = models.ForeignKey(Cart)
 user = models.ForeignKey(UserCheckout, null=True)
 billing_address = models.ForeignKey(UserAddress, 
 related_name='billing_address', null=True)
 shipping_address = models.ForeignKey(UserAddress, 
 related_name='shipping_address', null=True)
 shipping_total_price = models.DecimalField(max_digits=50, 
 decimal_places=2, default=5.99)   
 order_total = models.DecimalField(max_digits=50, decimal_places=2, )
 order_id = models.CharField(max_length=20, null=True, blank=True)
 paymethod = models.CharField(max_length=120, choices=CHOICES, 
 default='CreditCard')
 

 def __unicode__(self):
 return str(self.cart.id)


 *sellers/mixins.py*


 import datetime

 from django.db.models import Count, Min, Sum, Avg, Max

 from dress.mixins import LoginRequiredMixin
 from orders.models import Transaction, Order
 from products.models import Product

 from .models import SellerAccount



 class SellerAccountMixin(LoginRequiredMixin, object):
 account = None
 products = []
 transactions = []
 orders = []

 def get_account(self):
 user = self.request.user
 accounts = SellerAccount.objects.filter(user=user)
 if accounts.exists() and accounts.count() == 1:
 self.account = accounts.first()
 return accounts.first()
 return None

 def get_products(self):
 account = self.get_account()
 products = Product.objects.filter(seller=account)
 self.products = products
 return products

def get_sold_products(self):
 products = self.get_products()
 **
   THIS IS THE PROBLEM AREA ? i want to show orders of the 
 products i got from (products = self.get_products()).
 keeping this thing in mind that order is completed if its 
 status set to be 'paid'
 OR
 In other words i want to show products of the user that is 
 logged in if the status of that products 

Re: Issue in filtering .....(want to show only the products that are sold and have status of paid in orders App)

2016-09-19 Thread Asad Jibran Ahmed
How are you associating a product with an order? Is there a way to get a
list of products sold for each order?

Asad Jibran Ahmed 
http://blog.asadjb.com

On Tue, Sep 20, 2016 at 9:24 AM, Shamaila Moazzam <
shamaila.moaz...@gmail.com> wrote:

> Thanks for you kind response ...I am stuck in it :(
>
> I have seller as a foreign key in Product model..
>
> *products/models.py*
>
> class Product(models.Model):
> user = models.ForeignKey(settings.AUTH_USER_MODEL)
> seller = models.ForeignKey(SellerAccount)
>
> title = models.CharField(max_length=120)
> description = models.TextField(blank=True, null=True)
> price = models.DecimalField(decimal_places=2, max_digits=20)
>
>
>
>
>
> On Tuesday, September 20, 2016 at 10:09:01 AM UTC+5, Asad Jibran Ahmed
> wrote:
>>
>> Hi,
>>  While you didn't show us the Product model, I assume it has a ForeignKey
>> to the Order model. To filter for Products that have an Order with a
>> sold status, you should look at the documentation for filtering on
>> relationships at https://docs.djangoproject.com
>> /en/1.10/topics/db/queries/#lookups-that-span-relationships.
>> Regards,
>> Jibran
>>
>> On Tuesday, September 20, 2016 at 9:04:18 AM UTC+4, Shamaila Moazzam
>> wrote:
>>>
>>> hi
>>> I am a beginner in django/python * :(*
>>>
>>> I am making a dashboard of sellers App.
>>> I am stuck in filtering orders of the products according to the logged
>>> in user(seller)
>>>
>>> *sellers/models.py*
>>>
>>> from django.conf import settings
>>> from django.core.urlresolvers import reverse
>>> from django.db import models
>>> from django.contrib.auth.models import User
>>>
>>>
>>>
>>> class SellerAccount(models.Model):
>>> user = models.ForeignKey(User)
>>> managers = models.ManyToManyField(settings.AUTH_USER_MODEL,
>>> related_name="manager_sellers", blank=True)
>>> active = models.BooleanField(default=False)
>>> timestamp = models.DateTimeField(auto_now_add=True, auto_now=False)
>>>
>>>
>>> def __unicode__(self):
>>> return str(self.user.username)
>>>
>>> def get_absolute_url(self):
>>> return reverse("products:vendor_detail", kwargs={"vendor_name":
>>> self.user.username})
>>>
>>>
>>> *orders/models.py*
>>>
>>> class Order(models.Model):
>>> status = models.CharField(max_length=120,
>>> choices=ORDER_STATUS_CHOICES, default='created')
>>> cart = models.ForeignKey(Cart)
>>> user = models.ForeignKey(UserCheckout, null=True)
>>> billing_address = models.ForeignKey(UserAddress,
>>> related_name='billing_address', null=True)
>>> shipping_address = models.ForeignKey(UserAddress,
>>> related_name='shipping_address', null=True)
>>> shipping_total_price = models.DecimalField(max_digits=50,
>>> decimal_places=2, default=5.99)
>>> order_total = models.DecimalField(max_digits=50, decimal_places=2, )
>>> order_id = models.CharField(max_length=20, null=True, blank=True)
>>> paymethod = models.CharField(max_length=120, choices=CHOICES,
>>> default='CreditCard')
>>>
>>>
>>> def __unicode__(self):
>>> return str(self.cart.id)
>>>
>>>
>>> *sellers/mixins.py*
>>>
>>>
>>> import datetime
>>>
>>> from django.db.models import Count, Min, Sum, Avg, Max
>>>
>>> from dress.mixins import LoginRequiredMixin
>>> from orders.models import Transaction, Order
>>> from products.models import Product
>>>
>>> from .models import SellerAccount
>>>
>>>
>>>
>>> class SellerAccountMixin(LoginRequiredMixin, object):
>>> account = None
>>> products = []
>>> transactions = []
>>> orders = []
>>>
>>> def get_account(self):
>>> user = self.request.user
>>> accounts = SellerAccount.objects.filter(user=user)
>>> if accounts.exists() and accounts.count() == 1:
>>> self.account = accounts.first()
>>> return accounts.first()
>>> return None
>>>
>>> def get_products(self):
>>> account = self.get_account()
>>> products = Product.objects.filter(seller=account)
>>> self.products = products
>>> return products
>>>
>>>def get_sold_products(self):
>>> products = self.get_products()
>>> **
>>>   THIS IS THE PROBLEM AREA ? i want to show orders of the
>>> products i got from (products = self.get_products()).
>>> keeping this thing in mind that order is completed if its status
>>> set to be 'paid'
>>> OR
>>> In other words i want to show products of the user that is
>>> logged in if the status of that products are paid.
>>> *
>>> sold = Order.objects.all().filter('products')
>>> return sold
>>>
>>>
>>> *sellers/views.py*
>>>
>>> class SellerDashboard(SellerAccountMixin, FormMixin, View):
>>> form_class = NewSellerForm
>>> success_url = "/seller/"
>>> context["products"] = self.get_products()
>>>
>>>

Re: Issue in filtering .....(want to show only the products that are sold and have status of paid in orders App)

2016-09-19 Thread Shamaila Moazzam
Thanks for you kind response ...I am stuck in it :(

I have seller as a foreign key in Product model..

*products/models.py*

class Product(models.Model):
user = models.ForeignKey(settings.AUTH_USER_MODEL)
seller = models.ForeignKey(SellerAccount)
   
title = models.CharField(max_length=120)
description = models.TextField(blank=True, null=True)
price = models.DecimalField(decimal_places=2, max_digits=20)





On Tuesday, September 20, 2016 at 10:09:01 AM UTC+5, Asad Jibran Ahmed 
wrote:
>
> Hi,
>  While you didn't show us the Product model, I assume it has a ForeignKey 
> to the Order model. To filter for Products that have an Order with a sold 
> status, you should look at the documentation for filtering on relationships 
> at 
> https://docs.djangoproject.com/en/1.10/topics/db/queries/#lookups-that-span-relationships
> .
> Regards,
> Jibran
>
> On Tuesday, September 20, 2016 at 9:04:18 AM UTC+4, Shamaila Moazzam wrote:
>>
>> hi
>> I am a beginner in django/python * :(*
>>
>> I am making a dashboard of sellers App.
>> I am stuck in filtering orders of the products according to the logged in 
>> user(seller)
>>
>> *sellers/models.py*
>>
>> from django.conf import settings
>> from django.core.urlresolvers import reverse
>> from django.db import models
>> from django.contrib.auth.models import User
>>
>>
>>
>> class SellerAccount(models.Model):
>> user = models.ForeignKey(User)
>> managers = models.ManyToManyField(settings.AUTH_USER_MODEL, 
>> related_name="manager_sellers", blank=True)
>> active = models.BooleanField(default=False)
>> timestamp = models.DateTimeField(auto_now_add=True, auto_now=False)
>>
>>
>> def __unicode__(self):
>> return str(self.user.username)
>>
>> def get_absolute_url(self):
>> return reverse("products:vendor_detail", kwargs={"vendor_name": 
>> self.user.username})
>>
>>
>> *orders/models.py*
>>
>> class Order(models.Model):
>> status = models.CharField(max_length=120, 
>> choices=ORDER_STATUS_CHOICES, default='created')
>> cart = models.ForeignKey(Cart)
>> user = models.ForeignKey(UserCheckout, null=True)
>> billing_address = models.ForeignKey(UserAddress, 
>> related_name='billing_address', null=True)
>> shipping_address = models.ForeignKey(UserAddress, 
>> related_name='shipping_address', null=True)
>> shipping_total_price = models.DecimalField(max_digits=50, 
>> decimal_places=2, default=5.99)   
>> order_total = models.DecimalField(max_digits=50, decimal_places=2, )
>> order_id = models.CharField(max_length=20, null=True, blank=True)
>> paymethod = models.CharField(max_length=120, choices=CHOICES, 
>> default='CreditCard')
>> 
>>
>> def __unicode__(self):
>> return str(self.cart.id)
>>
>>
>> *sellers/mixins.py*
>>
>>
>> import datetime
>>
>> from django.db.models import Count, Min, Sum, Avg, Max
>>
>> from dress.mixins import LoginRequiredMixin
>> from orders.models import Transaction, Order
>> from products.models import Product
>>
>> from .models import SellerAccount
>>
>>
>>
>> class SellerAccountMixin(LoginRequiredMixin, object):
>> account = None
>> products = []
>> transactions = []
>> orders = []
>>
>> def get_account(self):
>> user = self.request.user
>> accounts = SellerAccount.objects.filter(user=user)
>> if accounts.exists() and accounts.count() == 1:
>> self.account = accounts.first()
>> return accounts.first()
>> return None
>>
>> def get_products(self):
>> account = self.get_account()
>> products = Product.objects.filter(seller=account)
>> self.products = products
>> return products
>>
>>def get_sold_products(self):
>> products = self.get_products()
>> **
>>   THIS IS THE PROBLEM AREA ? i want to show orders of the 
>> products i got from (products = self.get_products()).
>> keeping this thing in mind that order is completed if its status 
>> set to be 'paid'
>> OR
>> In other words i want to show products of the user that is logged 
>> in if the status of that products are paid.
>> *
>> sold = Order.objects.all().filter('products')
>> return sold
>>
>>
>> *sellers/views.py*
>>
>> class SellerDashboard(SellerAccountMixin, FormMixin, View):
>> form_class = NewSellerForm
>> success_url = "/seller/"
>> context["products"] = self.get_products()
>>
>> context["sold_products"] = self.get_sold_products()
>>
>> *sellers/dashboard.html*
>>
>> {{ sold_products }}
>>
>> i hope someone will definitely figure out my problem
>> regards
>>
>

-- 
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 

Re: Issue in filtering .....(want to show only the products that are sold and have status of paid in orders App)

2016-09-19 Thread Asad Jibran Ahmed
Hi,
 While you didn't show us the Product model, I assume it has a ForeignKey 
to the Order model. To filter for Products that have an Order with a sold 
status, you should look at the documentation for filtering on relationships 
at 
https://docs.djangoproject.com/en/1.10/topics/db/queries/#lookups-that-span-relationships.
Regards,
Jibran

On Tuesday, September 20, 2016 at 9:04:18 AM UTC+4, Shamaila Moazzam wrote:
>
> hi
> I am a beginner in django/python * :(*
>
> I am making a dashboard of sellers App.
> I am stuck in filtering orders of the products according to the logged in 
> user(seller)
>
> *sellers/models.py*
>
> from django.conf import settings
> from django.core.urlresolvers import reverse
> from django.db import models
> from django.contrib.auth.models import User
>
>
>
> class SellerAccount(models.Model):
> user = models.ForeignKey(User)
> managers = models.ManyToManyField(settings.AUTH_USER_MODEL, 
> related_name="manager_sellers", blank=True)
> active = models.BooleanField(default=False)
> timestamp = models.DateTimeField(auto_now_add=True, auto_now=False)
>
>
> def __unicode__(self):
> return str(self.user.username)
>
> def get_absolute_url(self):
> return reverse("products:vendor_detail", kwargs={"vendor_name": 
> self.user.username})
>
>
> *orders/models.py*
>
> class Order(models.Model):
> status = models.CharField(max_length=120, 
> choices=ORDER_STATUS_CHOICES, default='created')
> cart = models.ForeignKey(Cart)
> user = models.ForeignKey(UserCheckout, null=True)
> billing_address = models.ForeignKey(UserAddress, 
> related_name='billing_address', null=True)
> shipping_address = models.ForeignKey(UserAddress, 
> related_name='shipping_address', null=True)
> shipping_total_price = models.DecimalField(max_digits=50, 
> decimal_places=2, default=5.99)   
> order_total = models.DecimalField(max_digits=50, decimal_places=2, )
> order_id = models.CharField(max_length=20, null=True, blank=True)
> paymethod = models.CharField(max_length=120, choices=CHOICES, 
> default='CreditCard')
> 
>
> def __unicode__(self):
> return str(self.cart.id)
>
>
> *sellers/mixins.py*
>
>
> import datetime
>
> from django.db.models import Count, Min, Sum, Avg, Max
>
> from dress.mixins import LoginRequiredMixin
> from orders.models import Transaction, Order
> from products.models import Product
>
> from .models import SellerAccount
>
>
>
> class SellerAccountMixin(LoginRequiredMixin, object):
> account = None
> products = []
> transactions = []
> orders = []
>
> def get_account(self):
> user = self.request.user
> accounts = SellerAccount.objects.filter(user=user)
> if accounts.exists() and accounts.count() == 1:
> self.account = accounts.first()
> return accounts.first()
> return None
>
> def get_products(self):
> account = self.get_account()
> products = Product.objects.filter(seller=account)
> self.products = products
> return products
>
>def get_sold_products(self):
> products = self.get_products()
> **
>   THIS IS THE PROBLEM AREA ? i want to show orders of the 
> products i got from (products = self.get_products()).
> keeping this thing in mind that order is completed if its status 
> set to be 'paid'
> OR
> In other words i want to show products of the user that is logged 
> in if the status of that products are paid.
> *
> sold = Order.objects.all().filter('products')
> return sold
>
>
> *sellers/views.py*
>
> class SellerDashboard(SellerAccountMixin, FormMixin, View):
> form_class = NewSellerForm
> success_url = "/seller/"
> context["products"] = self.get_products()
>
> context["sold_products"] = self.get_sold_products()
>
> *sellers/dashboard.html*
>
> {{ sold_products }}
>
> i hope someone will definitely figure out my problem
> regards
>

-- 
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/457d2aa1-3893-4737-8fdf-a55ed08c06d3%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Issue in filtering .....(want to show only the products that are sold and have status of paid in orders App)

2016-09-19 Thread Shamaila Moazzam
hi
I am a beginner in django/python * :(*

I am making a dashboard of sellers App.
I am stuck in filtering orders of the products according to the logged in 
user(seller)

*sellers/models.py*

from django.conf import settings
from django.core.urlresolvers import reverse
from django.db import models
from django.contrib.auth.models import User



class SellerAccount(models.Model):
user = models.ForeignKey(User)
managers = models.ManyToManyField(settings.AUTH_USER_MODEL, 
related_name="manager_sellers", blank=True)
active = models.BooleanField(default=False)
timestamp = models.DateTimeField(auto_now_add=True, auto_now=False)


def __unicode__(self):
return str(self.user.username)

def get_absolute_url(self):
return reverse("products:vendor_detail", kwargs={"vendor_name": 
self.user.username})


*orders/models.py*

class Order(models.Model):
status = models.CharField(max_length=120, choices=ORDER_STATUS_CHOICES, 
default='created')
cart = models.ForeignKey(Cart)
user = models.ForeignKey(UserCheckout, null=True)
billing_address = models.ForeignKey(UserAddress, 
related_name='billing_address', null=True)
shipping_address = models.ForeignKey(UserAddress, 
related_name='shipping_address', null=True)
shipping_total_price = models.DecimalField(max_digits=50, 
decimal_places=2, default=5.99)   
order_total = models.DecimalField(max_digits=50, decimal_places=2, )
order_id = models.CharField(max_length=20, null=True, blank=True)
paymethod = models.CharField(max_length=120, choices=CHOICES, 
default='CreditCard')


def __unicode__(self):
return str(self.cart.id)


*sellers/mixins.py*


import datetime

from django.db.models import Count, Min, Sum, Avg, Max

from dress.mixins import LoginRequiredMixin
from orders.models import Transaction, Order
from products.models import Product

from .models import SellerAccount



class SellerAccountMixin(LoginRequiredMixin, object):
account = None
products = []
transactions = []
orders = []

def get_account(self):
user = self.request.user
accounts = SellerAccount.objects.filter(user=user)
if accounts.exists() and accounts.count() == 1:
self.account = accounts.first()
return accounts.first()
return None

def get_products(self):
account = self.get_account()
products = Product.objects.filter(seller=account)
self.products = products
return products

   def get_sold_products(self):
products = self.get_products()
**
  THIS IS THE PROBLEM AREA ? i want to show orders of the 
products i got from (products = self.get_products()).
keeping this thing in mind that order is completed if its status 
set to be 'paid'
OR
In other words i want to show products of the user that is logged 
in if the status of that products are paid.
*
sold = Order.objects.all().filter('products')
return sold


*sellers/views.py*

class SellerDashboard(SellerAccountMixin, FormMixin, View):
form_class = NewSellerForm
success_url = "/seller/"
context["products"] = self.get_products()
   
context["sold_products"] = self.get_sold_products()

*sellers/dashboard.html*

{{ sold_products }}

i hope someone will definitely figure out my problem
regards

-- 
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/0ffb09df-c7ea-4128-b678-136b07f3bf4f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.