On 9/10/06, Hawkeye <[EMAIL PROTECTED]> wrote:

> print "User's Foo: %s" % request.user.foo
>         <django.db.models.fields.related.RelatedManager object at 0x79e2d0>
> ==========

request.user.foo is a manager, same as User.objects. The manager
itself isn't a list of objects; you need to use one of the manager
methods (like all(), filter() etc) to get the actual objects in the
relation. So, something like

print "User's foo: %s" % request.user.foo.all()

should print what you are after.

> When I try to traverse the reference, I can't access any of the
> functions or attributes
> ==========
> request.user.foo.some_function()
>         AttributeError at /foos/1/
>         'RelatedManager' object has no attribute 'some_function'
> ==========

Again; request.user.foo isn't an object at this point. You need to
poke the related manager to get an object instance before you can
invoke a method on it.

# Get the first related object and call some_function on it.
request.user.foo.all()[0].some_function()

# Get the foo object with id=1, and call some_function on it
request.user.foo.get(id=1).some_function()

# Call some function on all related foo objects.
[f.some_function() for f in request.user.foo.all()]

Hope this helps.

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

Reply via email to