from django.db import models import uuid import datetime from django.contrib.auth.models import User from django.db import models from dashboard.models import Group VERIFY_CODE_TYPE_CHOICES = ( (0, 'register'), (1, 'password_recover'), ) class VerifyCode(models.Model): id = models.UUIDField('id', primary_key=True, default=uuid.uuid4) code = models.CharField('code', max_length=8, null=False) phone = models.CharField('phone', max_length=11, null=False) timeouted = models.DateTimeField('timeouted', null=False) category = models.IntegerField( 'category', choices=VERIFY_CODE_TYPE_CHOICES, default=0) added = models.DateTimeField(auto_now_add=True) updated = models.DateTimeField(auto_now=True) class Meta: ordering = ["-added"] def is_in_progress(self): now = datetime.datetime.now() return now <= self.timeouted def __str__(self): return self.phone + ':' + self.code class Notice(models.Model): id = models.UUIDField('id', primary_key=True, default=uuid.uuid4) user = models.ForeignKey(User, on_delete=models.CASCADE) content = models.CharField('内容', max_length=256, null=False) is_read = models.BooleanField('是否阅读', default=False) added = models.DateTimeField(auto_now_add=True) updated = models.DateTimeField(auto_now=True) class Meta: ordering = ["-added"] def is_in_progress(self): now = datetime.datetime.now() return now <= self.timeouted def __str__(self): return self.content + ':' + self.user.username class Task(models.Model): id = models.UUIDField('id', primary_key=True, default=uuid.uuid4) created_by = models.ForeignKey(User, on_delete=models.CASCADE) groups = models.ManyToManyField(Group) content = models.TextField('内容', null=True, blank=True) added = models.DateTimeField(auto_now_add=True) updated = models.DateTimeField(auto_now=True) def add_groups(self, groups): if not len(groups): groups = Group.objects.filter(status='开启') for g in groups: self.groups.add(g) class Meta: ordering = ["-added"] TASK_ADDITION_TYPE_CHOICES = ( (0, 'url'), (1, 'file'), (2, 'picture') ) class TaskAddition(models.Model): id = models.UUIDField('id', primary_key=True, default=uuid.uuid4) task = models.ForeignKey(Task, on_delete=models.CASCADE) category = models.IntegerField( 'category', choices=TASK_ADDITION_TYPE_CHOICES, default=1) url = models.CharField('url', max_length=256, null=True, blank=True) file = models.FileField( upload_to='task/file/%Y/%m/%d/', null=True, blank=True) picture = models.ImageField( upload_to='task/image/%Y/%m/%d/', null=True, blank=True) TASK_RECORD_STATUS_CHOICES = ( (0, '未完成'), (1, '完成'), ) class TaskRecord(models.Model): id = models.UUIDField('id', primary_key=True, default=uuid.uuid4) user = models.ForeignKey(User, on_delete=models.CASCADE) status = models.IntegerField( '状态', choices=TASK_RECORD_STATUS_CHOICES, default=0) added = models.DateTimeField(auto_now_add=True) updated = models.DateTimeField(auto_now=True) class Message(models.Model): id = models.UUIDField('id', primary_key=True, default=uuid.uuid4) send_from = models.ForeignKey(User, on_delete=models.CASCADE) send_to = models.ForeignKey(Group, on_delete=models.CASCADE) task = models.ForeignKey(Task, on_delete=models.CASCADE) added = models.DateTimeField(auto_now_add=True) updated = models.DateTimeField(auto_now=True) class Meta: abstract = True ordering = ["-added"] def __str__(self): return self.send_from + ':' + self.send_to class NormalMessage(Message): content = models.TextField('内容', null=True, blank=True) class URLMessage(Message): title = models.CharField('title', max_length=256, null=False) description = models.CharField('description', max_length=512, null=False) image = models.CharField('image', max_length=256, null=True, blank=True) url = models.CharField('url', max_length=256, null=True, blank=True) class FileMessage(Message): title = models.CharField('title', max_length=256, null=False) file = models.CharField('file', max_length=256, null=False) class ImageMessage(Message): title = models.CharField('title', max_length=256, null=False) picture = models.CharField('picture', max_length=256, null=False) class GroupRecord(models.Model): id = models.UUIDField('id', primary_key=True, default=uuid.uuid4) user = models.ForeignKey(User, on_delete=models.CASCADE) group = models.ForeignKey(Group, on_delete=models.CASCADE) enter_at = models.DateTimeField(auto_now=True) leave_at = models.DateTimeField(auto_now=True) added = models.DateTimeField(auto_now_add=True) updated = models.DateTimeField(auto_now=True)