working on tickets implementation
This commit is contained in:
@ -1,10 +1,67 @@
|
||||
# -*- encoding: utf-8 -*-
|
||||
"""
|
||||
Copyright (c) 2019 - present AppSeed.us
|
||||
"""
|
||||
|
||||
from datetime import timedelta, datetime
|
||||
|
||||
from django.db import models
|
||||
from django.contrib.auth.models import User
|
||||
from django.conf import settings
|
||||
from django.utils import timezone
|
||||
|
||||
# Create your models here.
|
||||
|
||||
class TicketPriority(models.Model):
|
||||
title = models.CharField(max_length=32)
|
||||
colour = models.CharField(max_length=7)
|
||||
|
||||
|
||||
class TicketTag(models.Model):
|
||||
title = models.CharField(max_length=32)
|
||||
colour = models.CharField(max_length=7)
|
||||
|
||||
|
||||
class Ticket(models.Model):
|
||||
title = models.CharField(max_length=60)
|
||||
description = models.TextField(max_length=650)
|
||||
author = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.CASCADE)
|
||||
create_timestamp = models.DateTimeField(editable=True, default=timezone.now)
|
||||
edit_timestamp = models.DateTimeField(editable=True, default=timezone.now)
|
||||
|
||||
def __str__(self):
|
||||
return f"#{self.id} • {self.title} • {self.author}"
|
||||
|
||||
@property
|
||||
def is_edited(self) -> bool:
|
||||
"""Returns boolean if the ticket is believed to have been edited.
|
||||
We assume a ticket is edited if the edit_timestamp doesn't match the create_timestamp.
|
||||
|
||||
Returns
|
||||
-------
|
||||
bool
|
||||
True if `self.edit_timestamp` doesn't match `self.create_timestamp`, False otherwise.
|
||||
"""
|
||||
|
||||
return self.create_timestamp != self.edit_timestamp
|
||||
|
||||
@property
|
||||
def is_older_than_day(self) -> bool:
|
||||
"""Returns boolean dependent on if `self.timestamp` is older than 24 hours.
|
||||
|
||||
Returns
|
||||
-------
|
||||
bool
|
||||
True if `self.timestamp` is older than 24 hours, False otherwise.
|
||||
"""
|
||||
|
||||
dayago = timezone.now() - timedelta(hours=24)
|
||||
return self.timestamp <= dayago
|
||||
|
||||
@property
|
||||
def timestamp(self) -> datetime:
|
||||
"""Returns `self.edit_timestamp` if `self.is_edited` is True, otherwise
|
||||
returns `self.create_timestamp`.
|
||||
|
||||
Returns
|
||||
-------
|
||||
datetime
|
||||
Either `self.edit_timestamp` or `self.create_timestamp`.
|
||||
"""
|
||||
|
||||
return self.edit_timestamp if self.is_edited else self.create_timestamp
|
||||
|
Reference in New Issue
Block a user