-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodels.py
More file actions
38 lines (29 loc) · 1.05 KB
/
models.py
File metadata and controls
38 lines (29 loc) · 1.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import django.contrib.auth.models
import django.db.models
class CompanyManager(django.contrib.auth.models.BaseUserManager):
def create_company(self, email, name, password=None, **extra_fields):
if not email:
raise ValueError('The Email must be set')
email = self.normalize_email(email)
company = self.model(
email=email,
name=name,
**extra_fields,
)
company.set_password(password)
company.save(using=self._db)
return company
class Company(django.contrib.auth.models.AbstractBaseUser):
email = django.db.models.EmailField(
unique=True,
max_length=120,
)
name = django.db.models.CharField(max_length=50)
token_version = django.db.models.IntegerField(default=0)
created_at = django.db.models.DateTimeField(auto_now_add=True)
is_active = django.db.models.BooleanField(default=True)
objects = CompanyManager()
USERNAME_FIELD = 'email'
REQUIRED_FIELDS = ['name']
def __str__(self):
return self.name