using select_related() and selecting DB table fields

View: New views
1 Messages — Rating Filter:   Alert me  

using select_related() and selecting DB table fields

by dbr-3 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


Hello..

.. brought this up in the IRC channel yesterday, but didn't come to a
final conclusion at the time.

My use-case is really simple; I'd like to do something like this from
the django DB API:
SELECT trackback.title, blog.name, blog.url FROM trackback INNER JOIN
blog ON trackback.blog_id = blog.id

The only way of getting certain fields from a table (that I have found)
is using values() on a QuerySet, but then I have a ValueQuerySet, which
wont be populated by select_related().

Now, I understand this would break the model object to table row
mapping of the QuerySet (objects woulnd't be complete if some fields
were missing), but that kind of query is such a common one that I'm
really surprised that I now seem to have to resort to hit the database
twice to fetch data through the db-relationship. That or resorting to
raw SQL.

Now, I'll be the first to admit that I just recently got started with
django, so my knowledge and/or reasoning about this may be totally off.
Also, I'm sorry if this is a FAQ, but I didn't find much about this
searching the mailing list archives and the docs on the homepage.

Also, if this is something that would be a welcome addition to the
codebase (through a specialised QuerySet perhaps), I could probably
help out.

Regards,
Daniel


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Django developers" group.
To post to this group, send email to django-developers@...
To unsubscribe from this group, send email to django-developers-unsubscribe@...
For more options, visit this group at http://groups.google.com/group/django-developers?hl=en
-~----------~----~----~----~------~----~------~--~---