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

后端 未结 5 1332
日久生厌
日久生厌 2021-02-02 07:09

I have a Django model with some fields that have default values specified. I am looking to grab the default value for one of these fields for us later on in my code. Is there

5条回答
  •  借酒劲吻你
    2021-02-02 07:36

    As of Django 1.9.x you may use:

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

提交回复
热议问题