Hi
just starting to use Django, am stuck with the following problem:
Given
class A(models.Model):
...some fields...
class B(models.Model):
A = models.ForeignKey(A)
....some fields...
I would like to generate a Queryset that returns values from both
tables, ie in SQL
SELECT A.field1, A.field2, B.field1, B.field2
FROM A, B
WHERE A.id = B.A_id AND some filter on A AND .. some further
conditions to ensure only one row from table B is matched
So far, I found a way to achieve this using the extra operator:
A.objects.filter(..some filter on A..).extra(select={'field1': "select
B.field1 from B ...", 'field2': 'select B.field2 from B ..."})
This quickly becomes clumsy as the number of fields in table B
increases. There must be a better way? As I couldnt find anything in
the documentation, I would appreciate a nudge in the right direction.
Thanks
Markus
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to [email protected]
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
-~----------~----~----~----~------~----~------~--~---