Excellent!! - req.country.subregion.subregion_name works like a charm
- thank you so much!

I figured it was probably just me not understanding the correct way to
ask django for the info.  I'm so used to php and raw sql that there's
a bit of a learning curve.

On Mar 17, 11:36 pm, "RajeshD" <[EMAIL PROTECTED]> wrote:
> > For example: using python manage.py shell
> > ---------------------------------------------------------------------------------------------
> > from myproject.myapp.models import *
> > req = Request.select_related().get(request_id = '000N07')
> > req.request_id
> >      outputs -> '000N07'
> > req.country
> >      outputs -> 'United States of America'
> > req.partner_id
> >      outputs -> 'Some Partner'
> > req.subregion_name
> >     outputs -> AttributeError: 'Request' object has no attribute
> > 'subregion_name'
> > -----------------------------------------------------------------------------------------------
>
> You want to say this instead:
>
> req.country.subregion.subregion_name
>
>
>
> > Django seems to be following the first level of Foreign Keys just fine
> > (it got the actual country & partner name and not just the id#), but
> > it doesn't seem to be making the link from country to region/
> > subregion.  So what am I doing wrong?  Is my syntax bad?  Am I using
> > the wrong attribute?  (I'm not exactly sure how django is choosing the
> > names although I would assume it's from the model.
>
> Select_related preloads foreign keyed objects into your query object.
> In other words, it saves you on database roundtrips when fetching
> objects related to your query object. It's a performance improvement
> feature. Even if you didn't use select_related() in your calls above,
> Django will still fetch related objects for you but it will make
> individual database call to get each such object.


--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to