[Answered ]-How to get properties of a model attribute?

2👍

Django models _meta.fields is fields list that you can access to get field attributes:

>>> from django.contrib.auth.models import User
>>> u = User.objects.all()[0]
>>> u._meta.fields[1].__class__.__name__
'CharField'
>>> u._meta.fields[1].name
'username'
>>> u._meta.fields[1].max_length
30
>>> u._meta.fields[1].blank
False
# ...
👤ndpu

0👍

You can get attributes of a specific field by using get_field()

MyClass._meta.get_field(‘attributeA’).max_length

👤aysum

Leave a comment