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
- [Answered ]-Django admin aggregation
- [Answered ]-Python Django cache vs store in model field? Which is more efficient?
- [Answered ]-Scrape data from paginated contents
- [Answered ]-How to properly configure ROOT_URLCONF
Source:stackexchange.com