[Answered ]-How would I update a field to set a default value?

1👍

class YourModel(models.Model):
      your_given_field = models.CharField(max_length=100, default='default_value')

def save(self, *args, **kwargs):
    if not self.your_given_field:
        self.your_given_field = 'default_value'
    super().save(*args, **kwargs)

0👍

I think by explicitly trying to save the field as null you are overriding the default value. Try and update the object only if the variable exists.

my_variable = None

if my_variable:
    my_object.my_field = my_variable

if you post more of your code i could help more

Leave a comment