4👍
✅
Just check the class of the field using isinstance()
:
simple_field_names = [field.name for field in Info._meta.fields
if field.name != 'id' and
not isinstance(field, models.ForeignKey)]
If you want to get list of text fields only then you can pass a list of required classes to isinstance()
function:
text_field_names = [field.name for field in Info._meta.fields
if isinstance(field, (models.CharField, models.TextField))]
Source:stackexchange.com