Hi all,
Given the following simple models:
from django.db import models
class A(models.Model):
att=models.CharField(max_length=256)
class B(models.Model):
fk = models.ForeignKey(A)
My question is , if I have a variable of B class, how can I know what
is the model its 'fk' is refering to at runtime ?
Acctually I want do something like the following:
>>> b = B
>>> fk = [ f for f in b._meta.fields if f.get_internal_type()=="ForeignKey"
>>> ][0] # find the foreign key field at runtime
>>> queryset_of_a = fk.datamanager_of_A.all() # I know this is wrong. here i
>>> just want to show what i want: get the queryset of A class at runtime from
>>> the B side. what is the correct way ?
--
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.