[Fixed]-Django – How to get the max_length of a field


You can use the Model _meta API for accessing details of your model’s fields.

Here’s an example:

class MyModel(models.Model):
    title = models.CharField(max_length=200)

# retrieve the max_length

The _meta became a formal API in Django version 1.8. The documentation can be found at https://docs.djangoproject.com/en/stable/ref/models/meta/

Leave a comment