I want to know if there is a way programmatically of finding the default assigned to a field on any model, I have the model instance and the field names.
In the below model I would have to get the default from u_value, allow_profile and disabled if they are Null to be able to save the data correctly. The Database is Firebird
Eg model:
class Fitting(models.Model):
uuid = UUIDField(primary_key=True)
bought_in_control_panel_file = models.ForeignKey(BoughtInControlPanelFile, db_column='bought_in_control_panel_file_id',null=True, blank=True)
name = models.CharField(_('name'),null=True, blank=False,max_length=255)
code = models.CharField(_('Code'),null=True, blank=True,max_length=255)
fire_rating = models.ForeignKey(FireRating, db_column='fire_rating_id',null=True, blank=True)
u_value = models.FloatField(_('U-value'),default=0)
acoustic_rating = models.FloatField(_('Acoustic Rating'),default=0)
allow_profile = models.BooleanField(default=0)
disabled = models.BooleanField(default=0)
date_time_updated = models.DateTimeField(null=True, blank=True, auto_now=True)
model_field.get_default() returns the default assigned to a model field
Example: