from django.db import models
from django.contrib import admin
from django.contrib.auth.models import User
import bigint_patch


class UserExtraAttr(models.Model):
    user = models.ForeignKey(User)
    expire_dt = models.DateField(auto_now=False,
                                 auto_now_add=False, null=False)
    accounttype = models.IntegerField()

admin.site.register(UserExtraAttr)


class Project(models.Model):
    id = models.AutoField(primary_key=True)
    name = models.TextField(blank=False)
    start_dt = models.DateField(auto_now=False, auto_now_add=False, null=False, blank=False)
    end_dt = models.DateField(auto_now=False, auto_now_add=False, null=True, blank=True)
    sortkey = models.IntegerField(null=False)

    def __unicode__(self):
        return self.name

admin.site.register(Project)


class Job(models.Model):
    id = models.AutoField(primary_key=True)
    name = models.TextField(blank=False)
    sortkey = models.IntegerField(null=False)
    invalid = models.BooleanField(default=False)

    def __unicode__(self):
        return self.name

admin.site.register(Job)


class Task(models.Model):
    id = models.AutoField(primary_key=True)
    name = models.TextField(blank=False)
    job = models.ForeignKey('Job')
    sortkey = models.IntegerField(null=False)
    invalid = models.BooleanField(default=False)

    def __unicode__(self):
        return '%s' % (self.name)

admin.site.register(Task)


class ProjectWorker(models.Model):
    id = models.AutoField(primary_key=True)
    user = models.ForeignKey(User)
    project = models.ForeignKey('Project')
    job = models.ForeignKey('Job')
    invalid = models.BooleanField(default=False)

    def __unicode__(self):
        return '%s - %s' % (self.project.name, self.user.username)

admin.site.register(ProjectWorker)


class UsedTaskTime(models.Model):
    id = bigint_patch.BigAutoField(primary_key=True)
    user = models.ForeignKey(User)
    project = models.ForeignKey('Project')
    task = models.ForeignKey('Task')
    taskdate = models.DateField(auto_now=False, auto_now_add=False, null=False)
    tasktime = models.TimeField(auto_now=False, auto_now_add=False, null=False)

    def __unicode__(self):
        return '%s - %s -%s - %s' % (self.project.name, self.task.name, self.user.username, self.tasktime)

admin.site.register(UsedTaskTime)

@@ -1,20 +1,36 @@
+import datetime%0A
 from django.db impor
@@ -572,32 +572,64 @@
 o_now_add=False,
+%0A                               
  null=False, bla
@@ -699,24 +699,54 @@
 w_add=False,
+%0A                             
  null=True, 
@@ -839,32 +839,309 @@
         
-return self.name
+if self.end_dt:%0A            if self.end_dt %3C datetime.date.today():%0A                return u'%25d : %25s %5Bclosed%5D' %25 (self.id, self.name)%0A            else:%0A                return u'%25d : %25s %5Bopened%5D' %25 (self.id, self.name)%0A        else:%0A            return u'%25d : %25s %5Bopened%5D' %25 (self.id, self.name)
 %0A%0Aadmin.
@@ -1410,24 +1410,154 @@
     
-return self.name
+if self.invalid:%0A            return u'%25d : %25s %5Binvalid%5D' %25 (self.id, self.name)%0A        else:%0A            return u'%25d : %25s' %25 (self.id, self.name)
 %0A%0Aad
@@ -1842,32 +1842,61 @@
 nicode__(self):%0A
+        if self.invalid:%0A    
         return '
@@ -1898,20 +1898,186 @@
 urn 
+u
 '%25
-s' %25 (self
+d : %25s (%25s) %5Binvalid%5D' %25 (%0A                self.id, self.name, self.job.name)%0A        else:%0A            return u'%25d : %25s (%25s)' %25 (%0A                self.id, self.name, self.job
 .nam
@@ -2369,32 +2369,61 @@
 nicode__(self):%0A
+        if self.invalid:%0A    
         return '
@@ -2425,54 +2425,253 @@
 urn 
+u
 '%25
-s - %25s' %25 (self.project.name, self.user.user
+d : %25s (%25s - %25s) %5Binvalid%5D' %25 (%0A                self.id, self.user.username, self.project.name, self.job.name)%0A        else:%0A            return u'%25d : %25s (%25s - %25s)' %25 (%0A                self.id, self.user.username, self.project.name, self.job.
 name
@@ -3119,18 +3119,30 @@
 urn 
+u
 '%25
-s -
+d : %5B%25s - %25s%5D
  %25s -
+ 
 %25s -
@@ -3153,74 +3153,123 @@
  %25 (
-self.project.name, self.task.name, self.user.username, self.taskti
+%0A            self.id, self.taskdate, self.tasktime,%0A            self.user.username, self.project.name, self.task.na
 me)%0A

change model display when admin mode.