4

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)

1 Answer 1

3

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

Sign up to request clarification or add additional context in comments.

1 Comment

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!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.