Hi all, I hope this is the right place to ask questions about using Django, if not, please point me in the right direction, I would appreciate it
I have a django application and it has a model that looks like this:
class Addon(models.Model):
class AddonEpic(models.TextChoices):
CONDO_CLEANING = "condo_cleaning"
HOUSE_CLEANING = "house_cleaning"
DRY_CLEANING = "dry_cleaning"
class AddonType(models.TextChoices):
SINGLE = "single"
MULTIPLE = "multiple"
label = models.CharField(max_length=128, null=False)
type = models.CharField(choices=AddonType.choices, null=False)
epic = models.CharField(choices=AddonEpic.choices, null=False)
price = models.DecimalField(max_digits=10, decimal_places=2, null=False)
duration = models.DecimalField(max_digits=6, decimal_places=2, null=False)
needs_additional_data = models.BooleanField(null=False)
icon = models.CharField(max_length=128, null=True)
groups = models.ManyToManyField(AddonGroup)
It worked perfectly with DRF, but now the business requirements evolved, and I need to add additional fields to the model depending on the epic
. For example, there should be a CondoCleaningAddon
with field is_included_in_general_cleaning
.
What would the easiest/most sustainable/most pythonic approach be? I considered leaving the addon model as is and creating child models CondoCleaningAddon
, HouseCleaningAddon
and DryCleaningAddon
. Another thought was to create CondoCleaningAddonDetails
and so on, and use either contenttypes
or inheritance with AddonDetails
base class. But due to lack of experience I find it hard to see the longer term implications of each decision, hoping someone can advise. Thank you!