2015-03-10 02:24:40 +00:00
|
|
|
from django.db import models
|
2015-03-10 04:14:17 +00:00
|
|
|
import datetime
|
|
|
|
from django.conf import settings
|
|
|
|
from orderable.models import Orderable
|
2015-03-10 02:24:40 +00:00
|
|
|
|
2015-03-10 04:14:17 +00:00
|
|
|
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
|
|
|
|
|
2015-03-10 04:14:17 +00:00
|
|
|
|
|
|
|
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
|
2015-03-10 04:14:17 +00:00
|
|
|
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))
|
2015-03-10 04:14:17 +00:00
|
|
|
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)
|