[Fixed]-Can i get models field type from a model queryset in Django?

39👍

I have the answer:

a.model._meta.get_field('g').get_internal_type()
👤victor

3👍

fields = [f.attname for f in Experience._meta.fields]
file_fields = []
print("FILE FIELDS : ", fields)
for field in fields:
    get_type = Experience._meta.get_field(field)
    print("GET TYPE :", get_type)
    field_type = get_type.__class__.__name__
    print(field, "FILE TYPE : ", field_type)
    if field_type == "FileField":
        file_fields.append(field)

This code can get the field types of django models.

Leave a comment