Hello
I am looking for a way to test if a model.field is of relational type. The purpose is to select the non relational fields of a model after using model._meta.get_fields()
Since you’re using model._meta.get_fields()
are you looking for something like the following?
Using one of my own models as an example:
>>> type(Inventory._meta.get_fields()[6]) == IntegerField
False
>>> type(Inventory._meta.get_fields()[6]) == ForeignKey
True
That is in manage.py shell
after importing IntegerField
and ForeignKey
from django.db.models