Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

147
Views
Common fields for different django models in one place

I have some columns that are repeated in multiple models. is there any solution to place them somewhere and use it any model?

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

You can achieve this by creating base classes and inheriting them in your models.

Example:

class TimestampsModel(models.Model):

    @classmethod
    def get_fields(cls, fields: tuple):
        return fields.__add__(('created_at', 'updated_at'))
    
    created_at = models.DateTimeField(("created_at"), auto_now_add=True)
    updated_at = models.DateTimeField(("updated_at"), auto_now=True)

You can also make it abstract and Django won't create migrations for this.

    class Meta:
        abstract = True

Finally, a model would be:

class Blog(baseModels.TimestampsModel):

    class Meta:
        db_table = "blog"

    title = models.CharField(max_length=100)
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!