]> git.frykholm.com Git - tranquillity.git/blame - customerportal/models.py
Djangocon coding
[tranquillity.git] / customerportal / models.py
CommitLineData
26235f08 1from django.db import models
40e726c7
MF
2from django.contrib.auth.models import User
3from django.contrib.auth.models import AbstractUser
4from django.contrib.auth.models import AbstractUser, BaseUserManager ## A new class is imported. ##
5from django.db import models
6from django.utils.translation import ugettext_lazy as _
7
8
9class UserManager(BaseUserManager):
10 """Define a model manager for User model with no username field."""
11
12 use_in_migrations = True
13
14 def _create_user(self, email, password, **extra_fields):
15 """Create and save a User with the given email and password."""
16 if not email:
17 raise ValueError('The given email must be set')
18 email = self.normalize_email(email)
19 user = self.model(email=email, **extra_fields)
20 user.set_password(password)
21 user.save(using=self._db)
22 return user
23
24 def create_user(self, email, password=None, **extra_fields):
25 """Create and save a regular User with the given email and password."""
26 extra_fields.setdefault('is_staff', False)
27 extra_fields.setdefault('is_superuser', False)
28 return self._create_user(email, password, **extra_fields)
29
30 def create_superuser(self, email, password, **extra_fields):
31 """Create and save a SuperUser with the given email and password."""
32 extra_fields.setdefault('is_staff', True)
33 extra_fields.setdefault('is_superuser', True)
34
35 if extra_fields.get('is_staff') is not True:
36 raise ValueError('Superuser must have is_staff=True.')
37 if extra_fields.get('is_superuser') is not True:
38 raise ValueError('Superuser must have is_superuser=True.')
39
40 return self._create_user(email, password, **extra_fields)
41
42
43class User(AbstractUser):
44 username = None
45 fortnox_external_id = models.IntegerField()
46 gpg_public_key = models.CharField(null=True, max_length=4096)
47 ssh_public_key = models.CharField(null=True, max_length=4096)
48 last_login = models.DateField(null=True)
49 cos_id = models.CharField(null=True, max_length=4096)
50 cos_contractid = models.CharField(null=True, max_length=4096)
51 cos_anlaggningsid = models.CharField(null=True, max_length=4096)
52 USERNAME_FIELD = 'email'
53 REQUIRED_FIELDS = ['fortnox_external_id']
54 objects = UserManager() ## This is the new line in the User model. ##
55
56class vps(models.Model):
57 user = models.ForeignKey(to=User, on_delete=models.CASCADE)
58 uuid = models.CharField(max_length=4096)
59
60class physical_server(models.Model):
61 user = models.ForeignKey(to=User, on_delete=models.CASCADE)
62 rack = models.CharField(max_length=4096)
63 unit = models.IntegerField()
64
65class IP(models.Model):
66 user = models.ForeignKey(to=User, on_delete=models.CASCADE)
67 cidr = models.CharField(max_length=4096)
68
26235f08 69
40e726c7
MF
70# graph resources
71# port on device (realtime) autodetect on description(Cust: fortnox_external_id)
72# cpu
73# memory
74# disks
75#