35 lines
910 B
Python
35 lines
910 B
Python
from django.db import models
|
|
from apps.workspaces.models import Workspace
|
|
|
|
from core.models.base import BaseModel
|
|
|
|
|
|
class Client(BaseModel):
|
|
workspace = models.ForeignKey(
|
|
Workspace,
|
|
on_delete=models.CASCADE,
|
|
related_name="clients",
|
|
)
|
|
|
|
name = models.CharField(max_length=255)
|
|
|
|
notes = models.TextField(blank=True)
|
|
|
|
class Meta:
|
|
db_table = "client"
|
|
ordering = ("-updated_at", "-created_at")
|
|
indexes = [
|
|
models.Index(fields=["id"], name="client_id_idx"),
|
|
models.Index(fields=["workspace"], name="client_workspace_idx"),
|
|
]
|
|
constraints = [
|
|
models.UniqueConstraint(
|
|
fields=["workspace", "name"],
|
|
name="unique_client_name_per_workspace",
|
|
condition=models.Q(is_deleted=False),
|
|
)
|
|
]
|
|
|
|
def __str__(self):
|
|
return self.name
|