Monday, December 6, 2010

Re: General question about NOT EXISTS...

Sorry for the double post. The table should have been A = Blog, B =
blogentry and C = entry

On Dec 7, 1:12 am, andy <flowar...@gmail.com> wrote:
> Well django has a ISNULL which I guess could be use to get the result
> that you want. I'm a bit new to django and have not done any many-to-
> many relationships as yeah but I'm guessing you could do something
> like this:
>
> Lest say table A = Blog, B = entry and C = blogentry
>
> Blog.objects.filter(entry__isnull=True) If I am correct this should
> return a list of blogs that does not have any entires.
>
> On Dec 7, 12:06 am, Wes Wagner <wes.wag...@gmail.com> wrote:
>
> > This is a generic question because I am a newbie and things are not
> > gelling quite 100% on how to write Q statements to get a filter to do
> > everything one wants.
>
> > Let's say you have Table A and Table B and Table C, where Table B has
> > a foreign key to table A and Table C (a manually constructed many to
> > many because it has extra data elements)
>
> > Now I want to build a list of all elements from table A, where not
> > exists a record in Table B that is related to table A and also has a
> > couple values = to something, and related to a particular table C
> > record)
>
> > In SQL this would look like:
>
> > select * from a where not exists (select * from B,C where
> > a.id=b.aforeignkey and c.id=b.cforeignkey and b.filter1=blah and
> > c.filter2=blah)
>
> > How does that look when you are building an object list in the Q( )...
> > style format? Where I am hung up is finding syntax examples of how to
> > do the functional equivalent of a sql where not exists clause.
>
> > Is there a way to do this without using .extra() and using just normal
> > django?
>
> > -Wes Wagner

--
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+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate