I am trying to obtain class information on a field inside a model, when I only know name of the field and name of the model (both plain strings). How is it possible?
I can load the model dynamically:
from django.db import models
model = models.get_model('myapp','mymodel')
Now I have field – ‘myfield’ – how can I get the class of that field?
If the field is relational – how to get related field?
Thanks a bunch!
You can use model’s
_metaattribute to get field object and from field you can get relationship and much more e.g. consider a employee table which has a foreign key to a department tablefrom django/db/models/options.py