39 lines
1.7 KiB
Python
39 lines
1.7 KiB
Python
from decimal import Decimal
|
|
|
|
from django.conf import settings
|
|
from django.core.validators import MinValueValidator
|
|
from django.db import models
|
|
|
|
from apps.companies.models import Company
|
|
|
|
class Project(models.Model):
|
|
company = models.ForeignKey(Company, on_delete=models.PROTECT, related_name="projects")
|
|
name = models.CharField("Название", max_length=200)
|
|
description = models.TextField("Описание", blank=True)
|
|
is_active = models.BooleanField("Активен", default=True)
|
|
created_at = models.DateTimeField(auto_now_add=True)
|
|
updated_at = models.DateTimeField(auto_now=True)
|
|
|
|
class Meta:
|
|
ordering = ("company__name", "name")
|
|
constraints = [models.UniqueConstraint(fields=("company", "name"), name="unique_project_name_per_company")]
|
|
|
|
def __str__(self):
|
|
return f"{self.company}: {self.name}"
|
|
|
|
|
|
class ProjectMember(models.Model):
|
|
project = models.ForeignKey(Project, on_delete=models.PROTECT, related_name="memberships")
|
|
user = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.PROTECT, related_name="project_memberships")
|
|
hourly_rate = models.DecimalField("Ставка в час", max_digits=12, decimal_places=2, validators=[MinValueValidator(Decimal("0"))])
|
|
is_active = models.BooleanField("Активен", default=True)
|
|
created_at = models.DateTimeField(auto_now_add=True)
|
|
updated_at = models.DateTimeField(auto_now=True)
|
|
|
|
class Meta:
|
|
ordering = ("project__company__name", "project__name", "user__username")
|
|
constraints = [models.UniqueConstraint(fields=("project", "user"), name="unique_project_member")]
|
|
|
|
def __str__(self):
|
|
return f"{self.user} — {self.project}"
|