django abstract models

Solutions on MaxInterview for django abstract models by the best coders in the world

showing results for - "django abstract models"
Matteo
16 Jun 2019
1from django.db import models
2
3
4class CommonInfo(models.Model):
5    created = models.DateTimeField(auto_now=True)
6    updated = models.DateTimeField(auto_now_add=True)
7
8    class Meta:
9        ordering = ['-created']
10        abstract = True
11
12# table housing the organizations (multiple tenants)
13class Tenant(CommonInfo):
14    name = models.CharField(max_length=255, unique=True)
15    business_phone_number = models.CharField(max_length=250)
16    business_email = models.EmailField()
17    is_active = models.BooleanField(default=True)
18    schema = models.CharField(max_length=255)
19    subdomain = models.CharField(max_length=255)
20    tenant_id = models.SlugField(blank=True)
21
22    def __str__(self):
23        return self.name
24
25# organizational departments db table
26class Department(CommonInfo):
27    name = models.CharField(max_length=255, unique=True)
28    
29    def __str__(self):
30        self.name