[Answered ]-Using a class as a part of another class in django models

2👍

Yes you can create the base class and inherit that class in another class like,

class BaseModel(models.Model):
    field1 = models.CharField()
    field2 = models.CharField()

    class Meta:
        abstract = True

And inherit this class in another model to get those same field,

# Now if you change any field in BaseModel, it will reflect in both the models
class MachineConfiguration(BaseModel):
    pass

class RequestDetails(BaseModel):
    field3 = models.CharField()

Leave a comment