creating first models
This commit is contained in:
50
apps/authentication/models.py
Normal file
50
apps/authentication/models.py
Normal file
@@ -0,0 +1,50 @@
|
||||
from django.db import models
|
||||
from django.contrib.auth.models import (
|
||||
AbstractUser
|
||||
)
|
||||
from apps.core.models import BaseModel
|
||||
|
||||
|
||||
class User(AbstractUser, BaseModel):
|
||||
mobile = models.CharField(max_length=18)
|
||||
national_code = models.CharField(max_length=16)
|
||||
photo = models.CharField(max_length=50)
|
||||
|
||||
def __str__(self):
|
||||
return f'{self.username} {self.last_name}-{self.last_login}'
|
||||
|
||||
def save(self, *args, **kwargs):
|
||||
super(User, self).save(*args, **kwargs)
|
||||
|
||||
|
||||
class Province(BaseModel):
|
||||
name = models.CharField(max_length=50)
|
||||
|
||||
def __str__(self):
|
||||
return f'{self.name}'
|
||||
|
||||
def save(self, *args, **kwargs):
|
||||
super(Province, self).save(*args, **kwargs)
|
||||
|
||||
|
||||
class Organization(BaseModel):
|
||||
name = models.CharField(max_length=50)
|
||||
type = models.CharField(max_length=50)
|
||||
province = models.ForeignKey(
|
||||
Province,
|
||||
on_delete=models.CASCADE,
|
||||
related_name="province_organization",
|
||||
null=True
|
||||
)
|
||||
parent_organization = models.ForeignKey(
|
||||
'Organization',
|
||||
on_delete=models.CASCADE,
|
||||
related_name='parents',
|
||||
null=True
|
||||
)
|
||||
|
||||
def __str__(self):
|
||||
return f'{self.name}-{self.type}'
|
||||
|
||||
def save(self, *args, **kwargs):
|
||||
super(Organization, self).save(*args, **kwargs)
|
||||
Reference in New Issue
Block a user