After replicating you test and it still failing and various other
experiments I downloaded the latest django trunk and it works fine!
Always check the version first Phoebe!

Sorry for the run around.

For the record here are the two queries - correct one first, the
difference is in the SELECT part of subquery, SELECT U1.`cat_id`
instead of SELECT U0.`id`

SELECT `town_subcategory`.`name` FROM `town_subcategory` WHERE NOT
(`town_subcategory`.`id` IN (SELECT U0.`id` FROM `town_subcategory`
U0 LEFT OUTER JOIN `town_business` U1 ON (U0.`id` = U1.`cat_id`) WHERE
U1.`directory_ptr_id` IS NULL))

SELECT `town_subcategory`.`name` FROM `town_subcategory` WHERE NOT
(`town_subcategory`.`id` IN (SELECT U1.`cat_id` FROM
`town_subcategory` U0 LEFT OUTER JOIN `town_business` U1 ON (U0.`id` =
U1.`cat_id`) WHERE U1.`directory_ptr_id` IS NULL))



On Jan 31, 1:50 am, Malcolm Tredinnick <malc...@pointy-stick.com>
wrote:
> On Fri, 2009-01-30 at 07:46 -0800, phoebebright wrote:
> > Using your suggestion returns no values:
>
> Then there is something else going on in your code that is important and
> you haven't mentioned yet.
>
> If I use exactly the models you give:
>
>
>
> > class Category(models.Model):
> >     name = models.CharField(max_length=12, unique=True)
> >     description = models.TextField()
>
> > class Subcategory(models.Model):
> >     category = models.ForeignKey(Category)
> >     name =  models.CharField(max_length=30, unique=True)
>
> > class Directory(models.Model):
> >     name = models.CharField(max_length=60)
> >     phone = models.CharField(max_length=15)
>
> > class Business(Directory):
> >     cat = models.ForeignKey(Subcategory, limit_choices_to =
> > {'category__exact': 2})
>
> And I create a couple of categories, a few subcategories and a couple of
> businesses linked to some (but not all) of the subcategories, then the
> queryset I gave:
>
>         Subcategory.objects.values('name').exclude(business=None)
>
> returns exactly the right information (a non-empty collection of the
> subcategories related to businesses).
>
> To work out what is different in your situation, I suggest you start
> from that point, too. Copy and paste exactly what is above, create a few
> objects and try the queryset. Make sure you get back results (or we have
> to work out why you don't). Then work out what is different between that
> simpler example and your real code.
>
> For reference, the SQL query that is being generated for the above
> queryset is this:
>
> In [5]:
> models.Subcategory.objects.values('name').exclude(business=None).query.as_sql()
>
> Out[5]:
> ('SELECT`phoebe_subcategory`.`name` FROM `phoebe_subcategory` WHERE NOT
> (`phoebe_subcategory`.`id` IN (SELECTU0.`id` FROM `phoebe_subcategory`
> U0 LEFT OUTER JOIN `phoebe_business` U1 ON (U0.`id` = U1.`cat_id`) WHERE
> U1.`directory_ptr_id` IS NULL))',
>  ())
>
> (I happen to be using MySQL there, so the quoting of names will vary
> slightly on other databases, but it's the same query in all cases).
>
> Regards,
> Malcolm
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to