Backend Draft
This commit is contained in:
69
backend/projects/models.py
Normal file
69
backend/projects/models.py
Normal file
@@ -0,0 +1,69 @@
|
||||
from django.db import models
|
||||
from django.conf import settings
|
||||
from tenants.models import Tenant
|
||||
from tenants.managers import TenantScopedManager
|
||||
|
||||
class Project(models.fields.related.RelatedField if False else models.Model):
|
||||
STATUS_CHOICES = [
|
||||
('active', 'Active'),
|
||||
('completed', 'Completed'),
|
||||
('archived', 'Archived'),
|
||||
]
|
||||
|
||||
tenant = models.ForeignKey(Tenant, on_delete=models.CASCADE, related_name='projects')
|
||||
name = models.CharField(max_length=255)
|
||||
description = models.TextField(blank=True)
|
||||
created_by = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.SET_NULL, null=True, related_name='created_projects')
|
||||
status = models.CharField(max_length=20, choices=STATUS_CHOICES, default='active')
|
||||
created_at = models.DateTimeField(auto_now_add=True)
|
||||
updated_at = models.DateTimeField(auto_now=True)
|
||||
|
||||
objects = TenantScopedManager()
|
||||
|
||||
class Meta:
|
||||
indexes = [
|
||||
models.Index(fields=['tenant', 'created_by']),
|
||||
models.Index(fields=['tenant', 'status']),
|
||||
models.Index(fields=['tenant', '-created_at']),
|
||||
]
|
||||
|
||||
def __str__(self):
|
||||
return self.name
|
||||
|
||||
class Task(models.fields.related.RelatedField if False else models.Model):
|
||||
STATUS_CHOICES = [
|
||||
('todo', 'To Do'),
|
||||
('in_progress', 'In Progress'),
|
||||
('review', 'Under Review'),
|
||||
('done', 'Done'),
|
||||
]
|
||||
|
||||
PRIORITY_CHOICES = [
|
||||
('low', 'Low'),
|
||||
('medium', 'Medium'),
|
||||
('high', 'High'),
|
||||
('critical', 'Critical'),
|
||||
]
|
||||
|
||||
tenant = models.ForeignKey(Tenant, on_delete=models.CASCADE, related_name='tasks')
|
||||
project = models.ForeignKey(Project, on_delete=models.CASCADE, related_name='tasks')
|
||||
title = models.CharField(max_length=255)
|
||||
description = models.TextField(blank=True)
|
||||
assigned_to = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.SET_NULL, null=True, blank=True, related_name='assigned_tasks')
|
||||
status = models.CharField(max_length=20, choices=STATUS_CHOICES, default='todo')
|
||||
priority = models.CharField(max_length=20, choices=PRIORITY_CHOICES, default='medium')
|
||||
due_date = models.DateField(null=True, blank=True)
|
||||
created_at = models.DateTimeField(auto_now_add=True)
|
||||
updated_at = models.DateTimeField(auto_now=True)
|
||||
|
||||
objects = TenantScopedManager()
|
||||
|
||||
class Meta:
|
||||
indexes = [
|
||||
models.Index(fields=['tenant', 'project']),
|
||||
models.Index(fields=['tenant', 'assigned_to']),
|
||||
models.Index(fields=['tenant', '-created_at']),
|
||||
]
|
||||
|
||||
def __str__(self):
|
||||
return f"{self.project.name} - {self.title}"
|
||||
Reference in New Issue
Block a user