Re: Complex Query help - get items from the org to which the user belongs

2011-07-07 Thread Venkatraman S
On Thu, Jul 7, 2011 at 3:49 PM, DrBloodmoney wrote: > On Thu, Jul 7, 2011 at 12:04 AM, Venkatraman S wrote: > > I am doing some bechmarking on the performance of both the versions of > the > > query: > > 1. > > >

Re: Complex Query help - get items from the org to which the user belongs

2011-07-07 Thread DrBloodmoney
On Thu, Jul 7, 2011 at 12:04 AM, Venkatraman S wrote: > I am doing some bechmarking on the performance of both the versions of the > query: > 1. > Item.objects.filter(created_by__employees__org__in=u.employees_set.all().values_list('org')) > and > 2.

Re: Complex Query help - get items from the org to which the user belongs

2011-07-06 Thread Venkatraman S
I am doing some bechmarking on the performance of both the versions of the query: 1. Item.objects.filter(created_by__employees__org__in=u.employees_set.all().values_list('org')) and 2. Items.objects.extra(where=['created_by_id in (select e.user_id from myapp_employees e, myapp_organization o where

Re: Complex Query help - get items from the org to which the user belongs

2011-07-06 Thread Venkatraman S
On Wed, Jul 6, 2011 at 8:09 PM, Marc Aymerich wrote: > I swear this time it will work! > > Item.objects.filter(created_by__employees__org__in=u.employees_set.all().values_list('org')) > > I cried on seeing this ;) Thanks a tonne. Guess this will go into the django hall of

Re: Complex Query help - get items from the org to which the user belongs

2011-07-06 Thread Marc Aymerich
On Wed, Jul 6, 2011 at 2:46 PM, Venkatraman S wrote: > > > On Wed, Jul 6, 2011 at 2:10 PM, Marc Aymerich wrote: >> >> This one should work: >> Items.objects.filters(created_by__employee__org=A.org) > > Nope. Emp has a FK for User, not the other way round.

Re: Complex Query help - get items from the org to which the user belongs

2011-07-06 Thread Tom Evans
On Wed, Jul 6, 2011 at 2:40 PM, akaariai wrote: > Maybe this? > > user = current_user > user_org_employees = Employees.objects.filter(org=user.org) > user_org_items = > Items.objects.filter(created_by__in=user_org_employees) > No, users can belong to multiple organizations,

Re: Complex Query help - get items from the org to which the user belongs

2011-07-06 Thread akaariai
On Jul 5, 10:06 pm, Venkatraman S wrote: > I tried asking around in IRC, and stumbled on a few possible solutions, > would be great if someone shed some more light: > > I have the following models: > > class Organization(models.Model): >   name                =

Re: Complex Query help - get items from the org to which the user belongs

2011-07-06 Thread Venkatraman S
On Wed, Jul 6, 2011 at 2:10 PM, Marc Aymerich wrote: > This one should work: > Items.objects.filters(created_by__employee__org=A.org) > Nope. Emp has a FK for User, not the other way round. -- You received this message because you are subscribed to the Google Groups

Re: Complex Query help - get items from the org to which the user belongs

2011-07-06 Thread Marc Aymerich
On Wed, Jul 6, 2011 at 4:46 AM, Venkatraman S wrote: > > On Wed, Jul 6, 2011 at 2:26 AM, Marc Aymerich wrote: > >> Say there are 3 Users in an org : A, B and C with each creating 3,4,5 >> items respectively, and 'A' is the current user; then i need a

Re: Complex Query help - get items from the org to which the user belongs

2011-07-05 Thread Venkatraman S
On Wed, Jul 6, 2011 at 8:39 AM, Venkatraman S wrote: > > On Wed, Jul 6, 2011 at 12:36 AM, Venkatraman S wrote: > >> I tried asking around in IRC, and stumbled on a few possible solutions, >> would be great if someone shed some more light: >> >> I have the

Re: Complex Query help - get items from the org to which the user belongs

2011-07-05 Thread Venkatraman S
On Wed, Jul 6, 2011 at 12:36 AM, Venkatraman S wrote: > I tried asking around in IRC, and stumbled on a few possible solutions, > would be great if someone shed some more light: > > I have the following models: > > class Organization(models.Model): > name=

Re: Complex Query help - get items from the org to which the user belongs

2011-07-05 Thread Venkatraman S
On Wed, Jul 6, 2011 at 2:26 AM, Marc Aymerich wrote: > Say there are 3 Users in an org : A, B and C with each creating 3,4,5 items > respectively, and 'A' is the current user; then i need a query which returns > all these items(i.e, 12 items) when i supply A.. > >

Re: Complex Query help - get items from the org to which the user belongs

2011-07-05 Thread Marc Aymerich
On Tue, Jul 5, 2011 at 9:06 PM, Venkatraman S wrote: > I tried asking around in IRC, and stumbled on a few possible solutions, > would be great if someone shed some more light: > > I have the following models: > > class Organization(models.Model): > name=

Complex Query help - get items from the org to which the user belongs

2011-07-05 Thread Venkatraman S
I tried asking around in IRC, and stumbled on a few possible solutions, would be great if someone shed some more light: I have the following models: class Organization(models.Model): name= models.CharField(max_length=100, blank=False) class Employees(models.Model): org