58 lines
1.7 KiB
Python
58 lines
1.7 KiB
Python
from django.db import models
|
|
|
|
|
|
class Issue(models.Model):
|
|
class Status(models.TextChoices):
|
|
OPEN = "open"
|
|
IN_PROGRESS = "in_progress"
|
|
RESOLVED = "resolved"
|
|
CLOSED = "closed"
|
|
|
|
class Priority(models.TextChoices):
|
|
LOW = "low"
|
|
MEDIUM = "medium"
|
|
HIGH = "high"
|
|
|
|
project = models.ForeignKey(
|
|
"projects.Project",
|
|
on_delete=models.CASCADE,
|
|
related_name="issues",
|
|
)
|
|
reporter = models.ForeignKey(
|
|
"accounts.CustomUser",
|
|
on_delete=models.CASCADE,
|
|
related_name="reported_issues",
|
|
)
|
|
assignee = models.ForeignKey(
|
|
"accounts.CustomUser",
|
|
null=True,
|
|
blank=True,
|
|
on_delete=models.SET_NULL,
|
|
related_name="assigned_issues",
|
|
)
|
|
title = models.CharField(max_length=255)
|
|
description = models.TextField(blank=True)
|
|
status = models.CharField(max_length=20, choices=Status.choices, default=Status.OPEN)
|
|
priority = models.CharField(max_length=20, choices=Priority.choices, default=Priority.MEDIUM)
|
|
created_at = models.DateTimeField(auto_now_add=True)
|
|
updated_at = models.DateTimeField(auto_now=True)
|
|
|
|
class Meta:
|
|
ordering = ["-created_at"]
|
|
|
|
def __str__(self):
|
|
return self.title
|
|
|
|
|
|
class IssueComment(models.Model):
|
|
issue = models.ForeignKey(Issue, on_delete=models.CASCADE, related_name="comments")
|
|
author = models.ForeignKey("accounts.CustomUser", on_delete=models.CASCADE)
|
|
body = models.TextField()
|
|
created_at = models.DateTimeField(auto_now_add=True)
|
|
|
|
class Meta:
|
|
ordering = ["created_at"]
|
|
|
|
def __str__(self):
|
|
return f"Comment by {self.author} on {self.issue}"
|