Re: ManyToMany lookups

2009-10-21 Thread koenb

On 20 okt, 21:19, r_f_d  wrote:
> Why not do this:
>
> for p in products.objects.all():
>     for c in p.categories.all():
>          print p,' - ', c
>
> -richard
>
> On Oct 20, 7:57 am, Михаил Лукин  wrote:
>

This will obviously leave you with a lot of queries. Take a look at eg
django-selectreverse [1] for some help reducing your querycount for
this type of nested lists.

Koen

[1]: http://code.google.com/p/django-selectreverse/
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: ManyToMany lookups

2009-10-20 Thread r_f_d

Why not do this:

for p in products.objects.all():
for c in p.categories.all():
 print p,' - ', c

-richard

On Oct 20, 7:57 am, Михаил Лукин  wrote:
> As I know, each category has attribute product_set
>
> 2009/10/20 ausi1972 
>
>
>
>
>
> > I am trying to work out how to construct a queryset that contains
> > multiple records for a ManyToMany field.
>
> > The models are like this:
> > class products(models.Model)
> >    name = models.CharField()
> >    categories = models.ManyToManyField(Category)
>
> > class category(models.Model)
> >    name = models.Charfield()
>
> > So a product can be in many categories.
>
> > I am trying to pull out a list of products with their categories and
> > listing the product multiple times if it is in multiple categories.
>
> > i.e.
> > product1 - category1
> > product1 - category2
> > product2 - category1
>
> > Any help always appreciated.
> > Regards Ausi
>
> --
> regards,
> Mihail
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: ManyToMany lookups

2009-10-20 Thread Михаил Лукин
As I know, each category has attribute product_set

2009/10/20 ausi1972 

>
> I am trying to work out how to construct a queryset that contains
> multiple records for a ManyToMany field.
>
> The models are like this:
> class products(models.Model)
>name = models.CharField()
>categories = models.ManyToManyField(Category)
>
> class category(models.Model)
>name = models.Charfield()
>
> So a product can be in many categories.
>
> I am trying to pull out a list of products with their categories and
> listing the product multiple times if it is in multiple categories.
>
> i.e.
> product1 - category1
> product1 - category2
> product2 - category1
>
> Any help always appreciated.
> Regards Ausi
>
> >
>


-- 
regards,
Mihail

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



ManyToMany lookups

2009-10-20 Thread ausi1972

I am trying to work out how to construct a queryset that contains
multiple records for a ManyToMany field.

The models are like this:
class products(models.Model)
name = models.CharField()
categories = models.ManyToManyField(Category)

class category(models.Model)
name = models.Charfield()

So a product can be in many categories.

I am trying to pull out a list of products with their categories and
listing the product multiple times if it is in multiple categories.

i.e.
product1 - category1
product1 - category2
product2 - category1

Any help always appreciated.
Regards Ausi

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---