check for existence in bulk

2011-03-30 Thread dmitry b
Hi, is there a way to check in bulk for record existence and get back a map of results similar to what's returned by in_bulk(). In my case, I need to look up records by a unique field which is not the primary key and I don't want object instances back, just true or false. Thanks Dmitry -- You

Re: check for existence in bulk

2011-03-30 Thread Calvin Spealman
I think your best bet is MyModel.objects.filter(some_field__in=ok_values).count() == len(ok_values) On Wed, Mar 30, 2011 at 12:44 PM, dmitry b wrote: > Hi, > > is there a way to check in bulk for record existence and get back a > map of results similar to what's returned by in_bulk().  In my cas

Re: check for existence in bulk

2011-03-30 Thread Jason Culverhouse
On Mar 30, 2011, at 9:47 AM, Calvin Spealman wrote: > I think your best bet is > > MyModel.objects.filter(some_field__in=ok_values).count() == len(ok_values) > > On Wed, Mar 30, 2011 at 12:44 PM, dmitry b wrote: >> Hi, >> >> is there a way to check in bulk for record existence and get back a

Re: check for existence in bulk

2011-03-31 Thread dmitry b
thanks, that's what I ended up using. On Mar 30, 11:58 am, Jason Culverhouse wrote: > You could use values_list  and flat as in: > >    User.objects.filter(username__in =['jason', 'was', > 'here']).values_list('username', flat=True) > > returns a list: > >    [u'jason', u'was'] > > After that y