generated from Code-Institute-Org/ci-full-template
-
Notifications
You must be signed in to change notification settings - Fork 4
Home
Sirinya edited this page Apr 30, 2024
·
2 revisions
Considering creating a base model or mixin as models, most of the models contained the same fields, e.g.
# Creating the base model to be inherited by models
class BaseModel(models.Model):
field_1 = models.CharField(max_length=50)
field_2 = models.IntegerField()
field_3 = models.TimeField()
class Meta:
abstract = True
# implementation of BaseModel by inheritance as follows:
class ModelOne(BaseModel):
additional_field_1 = models.TextField()
# Creating the mixin to be reused by models
class MixinModel(models.Model):
field_1 = models.CharField(max_length=50)
field_2 = models.IntegerField()
field_3 = models.TimeField()
class Meta:
abstract = True
# Implementation of reusing the MixinModel
class ModelTwo(MixinModel):
additional_field_1 = models.TextField()
As the models had the same fields with no additional fields or behaviours, I chose to keep the models separate. Individual models allow for clarity and simplicity and make it more maintainable, as the codebase is more flexible and can evolve independently.
Footer Navbar