You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

69 lines
3.0 KiB

import uuid
from django.contrib.auth.models import User
from django.db import models
from django.core.validators import RegexValidator
# Create your models here.
class UserInfo(models.Model):
user = models.OneToOneField(User, on_delete=models.CASCADE)
phone_regex = RegexValidator(regex=r'^\+?1?\d{9,15}$', message="Phone number must be entered in the format: '+999999999'. Up to 15 digits allowed.")
phone_number = models.CharField(validators=[phone_regex], max_length=16)
def __str__(self):
return 'UserInfo: ' + self.user.username
class Client(models.Model):
user = models.OneToOneField(User, on_delete=models.CASCADE)
business_number = models.CharField(max_length=16)
def __str__(self):
return self.user.first_name + ' ' + self.user.last_name
class Provider(models.Model):
user = models.OneToOneField(User, on_delete=models.CASCADE)
sin = models.CharField(max_length=16)
def __str__(self):
return self.user.first_name + ' ' + self.user.last_name
class WorkType(models.Model):
uuid = models.UUIDField(default=uuid.uuid4, editable=False)
client = models.ForeignKey(Client, related_name='work_types', on_delete=models.CASCADE)
color = models.CharField(max_length=16)
label = models.CharField(max_length=100)
deleted = models.BooleanField(default=False)
def __str__(self):
return 'WorkType: ' + self.label + ' of ' + self.client.user.username
class Manage(models.Model):
uuid = models.UUIDField(default=uuid.uuid4, editable=False)
client = models.ForeignKey(Client, related_name='employees', on_delete=models.CASCADE)
provider = models.ForeignKey(Provider, related_name='employers', on_delete=models.CASCADE)
note = models.CharField(max_length=500, blank=True)
approved = models.NullBooleanField(blank=True)
deleted = models.BooleanField(default=False)
def __str__(self):
return self.client.user.first_name + ' manages ' + self.provider.user.first_name
class Price(models.Model):
uuid = models.UUIDField(default=uuid.uuid4, editable=False)
management = models.ForeignKey(Manage, related_name='prices', on_delete=models.CASCADE)
work_type = models.ForeignKey(WorkType, on_delete=models.CASCADE)
amount = models.DecimalField(max_digits=8, decimal_places=2)
deleted = models.BooleanField(default=False)
class Shift(models.Model):
uuid = models.UUIDField(default=uuid.uuid4, editable=False)
price = models.ForeignKey(Price, on_delete=models.CASCADE)
set_price = models.DecimalField(max_digits=8, decimal_places=2, null=True)
set_date = models.DateField()
set_start = models.DateTimeField()
set_end = models.DateTimeField()
actual_start = models.DateTimeField(null=True)
actual_end = models.DateTimeField(null=True)
description = models.CharField(max_length=100, null=True)
chart = models.TextField(max_length=1000, null=True)
provider_approved = models.NullBooleanField(blank=True)
deleted = models.BooleanField(default=False)