How can I programmatically obtain the max_length of a Django model field?

Person._meta.get_field('name').max_length will give you this value. But having to use _meta suggests this is something you shouldn’t do in normal usage.

Edit: as Carl pointed out, this naming is misleading and it does seem quite acceptable to use it: http://www.b-list.org/weblog/2007/nov/04/working-models/

Read more at Django Docs:
https://docs.djangoproject.com/en/dev/ref/models/meta/#django.db.models.options.Options.get_field

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)