Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

Abstract Model inherit from another model django

from django.db import models

class BaseModel(models.Model):
    created_at = models.DateTimeField(auto_now_add=True)
    updated_at = models.DateTimeField(auto_now=True)
    
    class Meta:
        abstract = True



class Organisation(BaseModel):
    name = models.CharField("name of the organisation", max_length=200)

class Profile(BaseModel):
    user = models.ForeignKey(User, on_delete=models.CASCADE)
    bio = models.CharField("bio of the user", max_length=500)
 
PREVIOUS NEXT
Tagged: #Abstract #Model #inherit #model #django
ADD COMMENT
Topic
Name
5+7 =