Re: Django ORM question about lookups that span relationships

2011-04-26 Thread Carsten Fuchs
First of all, many thanks to everyone who replied in this thread, your posts were very interesting and helpful! On 24.04.2011 07:35, Alexander Schepanovski wrote: You can, with a subrequest: Blog.objects.filter(pk__in=Entry.objects.filter(pub_date__lte=date(2011, 4, 1), headline__contains='Lenn

Re: Django ORM question about lookups that span relationships

2011-04-23 Thread Alexander Schepanovski
> Yes, but while raw() has its uses, it's an interesting question: Is > there a way to do this with the Django ORM or not? It's always hard to > write raw queries in a database independent way, so there are good cases > where you want to avoid raw(). You can, with a subrequest: Blog.objects.filter

Re: Django ORM question about lookups that span relationships

2011-04-22 Thread Michael Radziej
On Fri, 22 Apr 2011 13:08:17 -0500, Jacob Kaplan-Moss wrote: > Blog.objects.raw('''SELECT * FROM blog Hey, that's cheating :-) > No, really -- if I was faced with a query, like this, that was easier > to express with SQL, I'd reach for `raw()` long before trying to > figure if I could twist th

Re: Django ORM question about lookups that span relationships

2011-04-22 Thread Jacob Kaplan-Moss
On Fri, Apr 22, 2011 at 5:36 AM, Michael Radziej wrote: > In SQL, it's something along > > SELECT ... FROM blog > JOIN entry e1 on e1.entry_id = blog.id >     AND e1.pub_date <= ... >     AND e1.headline LIKE "%Easter%" >     AND NOT exists >     ( SELECT id from entry e2 >       WHERE e2.entry_id

Re: Django ORM question about lookups that span relationships

2011-04-22 Thread Michael Radziej
On Fri, 22 Apr 2011 07:02:22 +0300, Oleg Lomaka wrote: > Blog.objects.filter(entry__pub_date__lte=date(2011, 4, 1), > entry__headline__contains='Easter > ').latest('pub_date') > > Or > > Blog.objects.filter(entry__pub_date__lte=date(2011, 4, 1), >

Re: Django ORM question about lookups that span relationships

2011-04-21 Thread Oleg Lomaka
).order_by('-pub_date')[0] On Thu, Apr 21, 2011 at 10:25 PM, Carsten Fuchs wrote: > > I'm currently reading < > http://docs.djangoproject.com/en/1.3/topics/db/queries/#lookups-that-span-relationships > >. > > What I seem to understand is how I can find al

Django ORM question about lookups that span relationships

2011-04-21 Thread Carsten Fuchs
Hi all, I'm currently reading <http://docs.djangoproject.com/en/1.3/topics/db/queries/#lookups-that-span-relationships>. What I seem to understand is how I can find all blogs that have entries that - where published *sometime* before or at April 1st, - and ha

Re: "Lookups that span relationships" + objects.exclude()

2009-05-05 Thread George Song
On 5/5/2009 12:47 AM, bweiss wrote: > So to enter a Qualification obtained, users choose a name from the > data in the Employee table, and a Qualification Type from the data in > that table, and then enter the remaining details (eg. date > obtained, expiry date). Also the Qualification table

Re: "Lookups that span relationships" + objects.exclude()

2009-05-05 Thread George Song
On 5/5/2009 12:47 AM, bweiss wrote: > Thanks Alex, that's really helpful and I'm certainly closer now! > However, after a fair bit of experimenting with that exclude() method, > I still can't quite get it to do what I need. > > I'm trying to get a list of all employees who do not have a > qualif

"Lookups that span relationships" + objects.exclude()

2009-05-05 Thread bweiss
Thanks Alex, that's really helpful and I'm certainly closer now! However, after a fair bit of experimenting with that exclude() method, I still can't quite get it to do what I need. I'm trying to get a list of all employees who do not have a qualification of a certain type (which I'llcall 'A1').

Lookups that span relationships

2006-06-07 Thread rob
Hi there, I'm having trouble with the documentation at http://www.djangoproject.com/documentation/db_api/#lookups-that-span-relationships It says that I can follow a 'reverse' relationship by using the lowercase name of the model, but when I try with the model below, I get an e