On 12/18/06, Austin Govella <[EMAIL PROTECTED]> wrote: > > I'm having trouble understanding the filtering. > > I've queried all articles related to a particular artist: > > articles = artist.article_set.all() > > I want to list the articles by type, so I filter the queryset by type: > > news = articles.filter(article_type__name__exact='news') > reviews = articles.filter(article_type__name__exact='review') > playlists = articles.filter(article_type__name__exact='playlist') > features = articles.filter(article__type__name__exact='feature') > > The news articles list correctly, but none of the other article types come up.
Assuming that Article has a relation called arcticle_type on model X, and model X has an attribute 'name', these queries all seem fine. When you say 'none of the other article types come up', I assume you mean 'the query sets are empty'. This leads to the obvious question - are you sure that an object matching your criteria actually exists? If you 'print articles', do you get objects that should match? > Two questions: First, is there a way to output all of the SQL and > returned query sets so I can get a better idea of what's going on? Yes, in two ways. From the query set, you can ask <some query set object>._get_sql_clause() which will return a slightly parsed version of the SQL (but you should be able to work out what SQL will actually get generated). Alternatively, you can ask the DB backend to list the SQL queries that have been issued: >>> from django.db import connection >>> Article.objects.all() >>> print connection.queries [....list of all SQL statements that have been executed on this cursor ...] > Second, are there any tutorials that directly address this type of > filtering? No tutorial; just the DB-API. Yours, Russ Magee %-) --~--~---------~--~----~------------~-------~--~----~ 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?hl=en -~----------~----~----~----~------~----~------~--~---