I have four models that I want to combine into one report. The manual SQL is pretty easy, three INNER JOINS. I just can't figure out how to get the ORM to do it. I'm using the auth app with a custom profile model and that seems to be the issue, since the User model doesn't have a foreignkey to the Profile model, that data isn't showing up in my QuerySet.
The tables: auth_user (standard Django) subscriber_profile (User foreign key) subscriber_order (User, Promo foreign keys) subscriber_promo (No foreign key) The report I want to run is sales by users who have used a particular promo code. I need some information from each table. SQL that works great: SELECT * FROM subscriber_order INNER JOIN subscriber_promo ON subscriber_order.promo_id = subscriber_promo.id INNER JOIN auth_user ON auth_user.id = subscriber_order.user_id INNER JOIN subscriber_profile ON subscriber_profile.user_id = auth_user.id; (The * is in place just to be concise, I only need a handful of fields so in the actual query they are specified) I seem to be one JOIN short with my ORM query, I can't access the profile data and can't figure out how to add it in there since auth_user has no foreign key. I know this has to be simple, but I'm way more familiar with SQL than Django's ORM. It makes sense that the profile data isn't there with what I'm feeding it, I just don't know what else to feed it. Any ideas? >>> data = Order.objects.select_related().get(user__order__promo=1) >>> data.user <User: jonknee> >>> data.promo <Promo: TEST> >>> data.profile AttributeError: 'Order' object has no attribute 'profile' --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---