obtaining related object from django.db.models.fields.related.ForeignKey

17 views
Skip to first unread message

Axel Rau

unread,
Apr 2, 2016, 10:55:54 AM4/2/16
to Django users
Hi all,

from a model object, I can get a related object shortcut,
using the name of the foreign key field:

>>> m1 = Mailbox.objects.get(pk=38)
>>> str(m1.localdomainfk)
'framailx.de'

But if I have the foreign key field instead of its name,
I can only get the pk of the related object:

>>> f1 = Mailbox._meta.get_field(‚localdomainfk')
>>> f1.value_from_object(m1)
7

Can anybody show me, how to get the related object
shortcut, if I have only the local object and the foreign key field?

Axel
-—
PGP-Key:29E99DD6 ☀ computing @ chaos claudius

Reply all
Reply to author
Forward
0 new messages