On Sat, 2006-09-23 at 18:35 +0100, Tom Smith wrote:
> I have a model that is trying to join (sloppily) across 3 tables.  
> KnownCategories are a "group by catalog" reduction of Product.catalog  
> (because I thought it would be quicker but I don't know if I'm  
> right)...they should join like this...
> 
> Product.catalog <------> KnownCategory.fk_name <------>  
> MetaCategory.name
> 
> 
> class Product(models.Model):
>       asin = models.CharField(maxlength=200)
>       title =  models.CharField(maxlength=200, db_index=True)
>       catalog  =  models.CharField(maxlength=200, default='',  db_index=True)
> 
> 
> class MetaCategory(models.Model):
>       name =  models.CharField(maxlength=200, core=True,  db_index=True,  
> unique=True)
> 
> class KnownCategory(models.Model):
>       meta_category = models.ManyToManyField(MetaCategory)
>       fk_name = models.ForeignKey(Product, to_field='catalog')
> 
> 
> ...from the above... I was trying to do something like this...
> 
>  >>> p = Product.objects.filter(metacategory__name='Book')

Since the MetaCategory model has no direct connection to the Product
model, this query stands no chance, as you discovered. Django doesn't do
the routing through the KnownCategory model transparently (in the
general case, there isn't always going to be a unique path, for a
start). So you need to write something like

        Product.objects.filter(fk_name_set__meta_category__name =
        'Book')
        
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users
-~----------~----~----~----~------~----~------~--~---

Reply via email to