Implementing django auth system with relational models

2016-08-17 Thread Shamaila Moazzam
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.


Can't make Django ORM work for multiple models

2016-08-17 Thread Shamaila Moazzam
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/c31416eb-37a7-40b3-98ca-a04258f46330%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Implementing django auth system with relational models

2016-08-17 Thread Shamaila Moazzam

@Mudassar this is exactly what I need.




On Wednesday, August 17, 2016 at 6:37:51 PM UTC+5, Shamaila Moazzam wrote:
>
> 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/10d630fa-7381-46c2-8d6b-35964b86dc09%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Implementing django auth system with relational models

2016-08-17 Thread Shamaila Moazzam
@Ludovic there is no error. Just I don't want to get all the products 
pre-populated. I need empty products field and only when user uploads 
products then it should show me products. Please advise

On Wednesday, August 17, 2016 at 6:37:51 PM UTC+5, Shamaila Moazzam wrote:
>
> 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/7e4ba681-de3c-4cda-9940-3312987e9c06%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Can't make Django ORM work for multiple models

2016-08-17 Thread Shamaila Moazzam
Thanks for reply Todor, But how to fix it in admin.py?

On Wednesday, August 17, 2016 at 7:52:20 PM UTC+5, Todor Velichkov wrote:
>
> I only intend to show products added by the shop owner.
>>
>  
> You can do this by using the reverse m2m relation between product and shop.
>
> products = Product.objects.filter(shop__shop_user=request.user)
>
> However, I think it's more suitable for the product to keep the M2M 
> relation, because naturally when you add a new product you would want to 
> choose its shops. If a product can belong to only one shop, then you can 
> even use a Foreign Key instead of M2M Field. 
>
> Also I need to register shop using built-in auth system so how do I do that
>>
>
> I'm not sure what is the question here, you have access to request.user, 
> just assign it to shop_user when you create a new shop. 
>
> should I add user field in Shop or in Product.
>>
>
> It really depends on what you need, you already mention that you need a 
> Shop.owner, so you can't go without user FK into Shop model. IF you think 
> you are gonna need and a Product owner/creator as well, then you can add 
> user FK to products as well. These things are not mutually exclusive.
>
>
>
> On Wednesday, August 17, 2016 at 4:37:51 PM UTC+3, 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/a5d1e310-47f3-4cb1-aa5b-47a294337ec5%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Can't make Django ORM work for multiple models

2016-08-17 Thread Shamaila Moazzam
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/e55d8864-bdd7-4b4a-ad70-7a3eadfa0dd3%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Implementing django auth system with relational models

2016-08-17 Thread Shamaila Moazzam


On Wednesday, August 17, 2016 at 6:37:51 PM UTC+5, Shamaila Moazzam wrote:
>
> 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/4f66b14f-6f23-4cac-a4cd-16be07454039%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Implementing django auth system with relational models

2016-08-17 Thread Shamaila Moazzam

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)

On Wednesday, August 17, 2016 at 9:23:31 PM UTC+5, ludovic coues wrote:
>
> Could you share your admin.py file ? 
>
> You might be interested into this part of the documentation: 
>
> https://docs.djangoproject.com/en/1.10/ref/contrib/admin/#django.contrib.admin.ModelAdmin.formfield_for_foreignkey
>  
>
> 2016-08-17 17:20 GMT+02:00 Shamaila Moazzam  >: 
> > @Ludovic there is no error. Just I don't want to get all the products 
> > pre-populated. I need empty products field and only when user uploads 
> > products then it should show me products. Please advise 
> > 
> > On Wednesday, August 17, 2016 at 6:37:51 PM UTC+5, Shamaila Moazzam 
> wrote: 
> >> 
> >> 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...@googlegroups.com . 
> > To post to this group, send email to django...@googlegroups.com 
> . 
> > Visit this

Re: Implementing django auth system with relational models

2016-08-18 Thread Shamaila Moazzam
ok thanx @  ludovic coues...
i will try this and then tell you
regards


On Thursday, August 18, 2016 at 2:38:46 AM UTC+5, ludovic coues wrote:
>
> Ok, sorry, I made a off by one error on the link :) 
>
> Try that: 
>
> # shops/admin.py 
> from django.contrib import admin 
> from products.models import Product 
> from .models import Shop 
>
> class ShopAdmin(admin.ModelAdmin): 
> def formfield_for_manytomany(self, db_field, request, **kwargs): 
> if db_field.name == "product": 
> kwargs["queryset"] = Product.objects.filter(user=request.user) 
> return super(ShopAdmin, 
> self).formfield_for_manytomany(db_field, request, **kwargs) 
>
> admin.site.register(Shop, ShopAdmin) 
>
> ### 
>
> It should give you the desired result 
>
> 2016-08-17 19:31 GMT+02:00 Shamaila Moazzam  >: 
> > 
> > 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) 
> > 
> > On Wednesday, August 17, 2016 at 9:23:31 PM UTC+5, ludovic coues wrote: 
> >> 
> >> Could you share your admin.py file ? 
> >> 
> >> You might be interested into this part of the documentation: 
> >> 
> >> 
> https://docs.djangoproject.com/en/1.10/ref/contrib/admin/#django.contrib.admin.ModelAdmin.formfield_for_foreignkey
>  
> >> 
> >> 2016-08-17 17:20 GMT+02:00 Shamaila Moazzam : 
> >> > @Ludovic there is no error. Just I don't want to get all the products 
> >> > pre-populated. I need empty products field and only when user uploads 
> >> > products then it should show me products. Please advise 
> >> > 
> >> > On Wednesday, August 17, 2016 at 6:37:51 PM UTC+5, Shamaila Moazzam 
> >> > wrote: 
> >> >> 
> >> >> 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 = ProductMan

Filtering models by user or by items

2016-09-01 Thread Shamaila Moazzam
am making a shops dashboard view .in that view i have used a mixin as
mentioned belowmy 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.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+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/CAFimi6wB1Ycnz2On4EALzvM5b0M-a17sB4PXpKFA5KdCiFK4WQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Filtering models by user or by items

2016-09-01 Thread Shamaila Moazzam
@ 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:
>
> What did you get with:
> products = Product.objects.filter(account=user)
> As it is inheriting user from get_shopaccount method.
>
> Regards,
> Mudassar
>
> On Thu, Sep 1, 2016 at 8:45 AM, Shamaila Moazzam  > wrote:
>
>> am making a shops dashboard view .in that view i have used a mixin as 
>> mentioned belowmy 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.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...@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
>>  
>> <https://groups.google.com/d/msgid/django-users/CAFimi6wB1Ycnz2On4EALzvM5b0M-a17sB4PXpKFA5KdCiFK4WQ%40mail.gmail.com?utm_medium=email&utm_source=footer>
>> .
>> 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+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/128fd036-6cdb-4031-b268-a420411f0b3e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Filtering models by user or by items

2016-09-02 Thread Shamaila Moazzam
Thanks@Mandeep...i will apply this also and let you know
actually i have changed my models and have put seller as F.K in Product.
after that
def get_products(self):
account = self.get_account()
products = Product.objects.filter(seller=account)
self.products = products
return products.

regards.
shamaila

On Fri, Sep 2, 2016 at 2:50 PM, mandeep444  wrote:

>
> 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.
>
>
> On Thursday, September 1, 2016 at 9:15:45 PM UTC+5:30, Shamaila Moazzam
> wrote:
>>
>> am making a shops dashboard view .in that view i have used a mixin as
>> mentioned belowmy 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.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 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+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/7496fc3e-e583-446f-b2de-6ef9ddcd888b%40googlegroups.com
> <https://groups.google.com/d/msgid/django-users/7496fc3e-e583-446f-b2de-6ef9ddcd888b%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>
> 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+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/CAFimi6yugRfF5AgOqKE8QTRU%3D4UsFG6qqS%3D5z3%3Db%2BimByRYO9g%40mail.gmail.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.


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

Re: Django filters with Foreign Key

2016-09-19 Thread Shamaila Moazzam

Hi ,

i am having the same problem ..with my sellers App .

can you share your solutionthat how you filter 

regards

On Monday, September 19, 2016 at 5:27:31 PM UTC+5, A.Khan wrote:
>
> I just got it done.
>
> Thanks.
>
> On Mon, Sep 19, 2016 at 4:19 AM, Ali khan  > wrote:
>
>> I've tried many ways but it ends with the same error that says:
>>
>> Cannot query "alikhan": Must be "User" instance.
>>
>> Where alikhan is admin user I've created with createsuperuser.
>>
>> Hate to bother you again but please advise.
>>
>> Regards,
>> Ali
>>
>> On Sun, Sep 18, 2016 at 11:08 PM, James Schneider > > wrote:
>>
>>> On Sep 18, 2016 10:22 PM, "Ali khan" > 
>>> wrote:
>>> >
>>> > Thank you for your kind response James.
>>> >
>>> > I must be doing something wrong but I thought that importing different 
>>> models and assigning them with variable may had help me to filter it out. I 
>>> will try your suggestion first to save your valued time and then will post 
>>> with result.
>>> >
>>> > Let me add a field for the seller in my "Orders" model like "seller = 
>>> models.ForeignKey(Seller)" and then filter it out.
>>> > But I tried that before still as per your suggestion I will do that 
>>> again.
>>> > Thanks again.
>>> >
>>>
>>> Once you do that, you can filter the orders with something like this:
>>>
>>> orders = Order.objects.filter(seller__user=user) 
>>>
>>> Inside of the filter function you defined. The way you are currently 
>>> doing it, you'll end up with Seller objects rather than Order objects.
>>>
>>> -James
>>>
>>> -- 
>>> 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/CA%2Be%2BciX6N3eQOnb5dP877WM0FEgj%2BAjt-QfT6anwE5jNMafx3Q%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+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/c77f059c-5ab6-43e3-a3bc-099e1aefab57%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


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

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)
>&g

how to show image with index in python as context variable

2017-04-25 Thread Shamaila Moazzam
hi,

i am trying to display a set of images with the use of index.
here is the code:
 
 {% for item in product.productimage_set.all %}


  
   
 {% endfor %}

 

the above code is displaying a set of images for one product .right.
i want to display it like {{ item[0].image.url }}
how can i do that ?

regards.
shamaila

-- 
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/51fd8360-f106-4cc2-bde0-9756e690a926%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Displaying the multiple images in the product detail page

2017-04-25 Thread Shamaila Moazzam
   
 {% for item in product.productimage_set.all %}


  
   
 {% endfor %}

 

this code is displaying different images of a single product ,but the 
question is how to slice them ,how to get image[0], image[1] ..on the 
product page...

can any one help??

On Tuesday, April 25, 2017 at 9:53:15 PM UTC+5, hadiqak...@gmail.com wrote:
>
> i am trying to display a set of images with the use of index.
> here is the code:
>  
>  {% for item in product.productimage_set.all %}
> 
>  style="height:100px;widht:50px"/>
>   
>
>  {% endfor %}
>
>  
>
> the above code is displaying a set of images for one product .right.
> i want to display it like {{ item[0].image.url }}
> how can i do that ?
>
> On Tuesday, April 25, 2017 at 6:05:02 PM UTC+5, Matthew Pava wrote:
>>
>> You could reference the images from your Product object like so:
>>
>> *product.image_set.all()*
>>
>> You may want to use models.ImageField, which inherits from 
>> models.FileField, instead of models.FileField
>>
>>  
>>
>> For more information:
>>
>> https://docs.djangoproject.com/en/1.11/topics/db/examples/many_to_one/
>>
>>
>> https://docs.djangoproject.com/en/1.11/ref/models/fields/#django.db.models.FileField
>>
>>  
>>
>>  
>>
>> In your template, you would probably want to use a for loop similar to 
>> this:
>>
>> *{% for i in product.image_set.all %}*
>>
>>
>>
>> {% endfor %}
>>
>>  
>>
>>  
>>
>> *From:* django...@googlegroups.com [mailto:django...@googlegroups.com] *On 
>> Behalf Of *hadiqak...@gmail.com
>> *Sent:* Tuesday, April 25, 2017 4:10 AM
>> *To:* Django users
>> *Subject:* Displaying the multiple images in the product detail page
>>
>>  
>>
>> I have created a separate image class where you can add images but I'm 
>> unable to show the multiple images on the product detail page. If anyone 
>> can guide me, it would be great. 
>>
>>  
>>
>> *class *Image(models.Model):
>> active = models.BooleanField(default=True)
>> product = models.ForeignKey(Product)
>> image = models.FileField(null=True)
>> title = models.CharField(max_length=120)
>>
>> *def *__unicode__(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...@googlegroups.com.
>> To post to this group, send email to djang...@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/fcff49ff-f999-41eb-a5bb-2abc567c2f73%40googlegroups.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+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/b38ae152-d2fd-4eb7-a3cc-cb2565ee017e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.