roadmap/project/models.py

64 lines
1.7 KiB
Python
Raw Normal View History

from django.db import models
import datetime
from django.conf import settings
from orderable.models import Orderable
STATUSES = (
(0, 'Upcoming'),
(1, 'Current'),
(2, 'Backlog'),
(3, 'Completed'),
)
class Project(models.Model):
title = models.CharField(max_length=256)
description = models.TextField(blank=True, null=True)
status = models.IntegerField(choices=STATUSES, default=0)
created_at = models.DateTimeField(auto_now_add=True)
updated_at = models.DateTimeField(auto_now=True)
2015-03-10 04:28:57 +00:00
def __unicode__(self):
return self.title
2015-03-10 04:51:06 +00:00
@property
def furthest_complete(self):
sorted_duedates = self.duedate_set.order_by("-title__sort_order")
for duedate in sorted_duedates:
if duedate.completed:
return unicode(duedate)
return None
class Category(Orderable):
title = models.CharField(max_length=256)
class Meta(Orderable.Meta):
verbose_name_plural = "Categories"
def __unicode__(self):
return self.title
class DueDate(models.Model):
title = models.ForeignKey("Category")
due = models.DateField(blank=True, null=True)
completed = models.BooleanField(default=False)
project = models.ForeignKey("Project")
2015-03-10 04:51:06 +00:00
@property
def completed_overdue_date(self):
if self.completed:
return "Completed"
if not self.due:
return ""
2015-03-10 04:51:06 +00:00
if self.due < datetime.date.today():
return "Overdue on {}".format(self.due.strftime(settings.DATE_FMT))
return self.due.strftime(settings.DATE_FMT)
class Meta:
verbose_name = "Due Date"
verbose_name_plural = "Due Dates"
def __unicode__(self):
return unicode(self.title)