Expose field types
thedrow opened this issue · comments
Omer Katz commented
Getting the field names is nice but I'd like to get the field types as well.
Jimmy Merrild Krag commented
I agree. This would be immensely useful. I am specifically looking for a method to determine whether a field is a FileField
and what storage it uses.
Jimmy Merrild Krag commented
I have found a way get this info without this app. I'd say this app is obsolete. Here is an example on a command traversing the information:
from django.core.management.base import BaseCommand
from django.apps import apps
from django.db import models
class Command(BaseCommand):
help = 'List all FieldFields in models'
def handle(self, *args, **options):
for model in apps.get_models():
for field_name in model._meta.get_all_field_names():
field = model._meta.get_field(field_name)
if isinstance(field, models.FileField):
print(model.__name__ + ':: ' + str(field_name) + ':\t' + type(field).__name__)
Omer Katz commented
It's not obsolete if you want to keep compatibility between Django versions
Jimmy Merrild Krag commented
@thedrow True that