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 an easy way to grab a particular field's default value from a model?
+1
A:
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
Daniel Roseman
2009-08-20 19:41:14
Anything with a _ is digging into the internals. See my question : http://stackoverflow.com/questions/1011946/django-know-if-property-is-the-default-value
Paul Tarjan
2009-09-12 05:54:07