How do I get the default value for a field in a Django model? How do I get the default value for a field in a Django model? django django

How do I get the default value for a field in a Django model?


TheModel._meta.get_field('the_field').get_default()


As of Django 1.9.x you may use:

field = TheModel._meta.get_field('field_name')default_value = field.get_default()


You can get the field like this:

myfield = MyModel._meta.get_field_by_name('field_name')

and the default is just an attribute of the field:

myfield.default