issue-tracker/forkosissuetracker/issuetracker_app/models.py

28 lines
873 B
Python
Raw Normal View History

from django.db import models
from simple_history.models import HistoricalRecords
from django.contrib.auth.models import User
class Issue(models.Model):
author = models.ForeignKey(User, on_delete=models.CASCADE)
title = models.CharField(max_length=128)
description = models.CharField(max_length=2048)
last_modified = models.DateTimeField(auto_now=True)
history = HistoricalRecords()
def get_absolute_url(self):
return f"/issues/{self.id}"
def __str__(self):
return f"{self.title}"
class Meta:
ordering = ["last_modified"]
class Comment(models.Model):
issue = models.ForeignKey(Issue, on_delete=models.CASCADE)
author = models.ForeignKey(User, on_delete=models.CASCADE)
body = models.CharField(max_length=2048)
last_modified = models.DateTimeField(auto_now=True)
history = HistoricalRecords()