views:

36

answers:

1

Scenario:

class BaseClass(models.Model):
    base_field = models.CharField(max_length=15, default=None)

class SubClass(BaseClass):
    # TODO set default value if base_field's value is None
    ...

ie. I need to be able to load a fixture into the database, providing a default value only if the base_field is None. Any help greatly appreciated! (note: BaseClass is not abstract)

+2  A: 

You could override the save method, check if base_field is set, otherwise set it to the default value.

ars
yeah, that's the path I didn't want to take, but it works so yay. i was hoping for something more like a constructor __new__ or __init__, but I don't fully understand the way those work yet so I think I'll go with your suggestion. thank you!
mkelley33