2020-08-20 07:38:42 +00:00
|
|
|
from django.db import models
|
2020-08-20 10:34:14 +00:00
|
|
|
import uuid
|
|
|
|
import datetime
|
2020-09-03 02:56:28 +00:00
|
|
|
from django.contrib.auth.models import User
|
2020-09-13 06:06:58 +00:00
|
|
|
from django.db import models
|
2020-09-03 02:56:28 +00:00
|
|
|
|
|
|
|
from dashboard.models import Group
|
2020-08-20 07:38:42 +00:00
|
|
|
|
2020-08-20 10:34:14 +00:00
|
|
|
VERIFY_CODE_TYPE_CHOICES = (
|
|
|
|
(0, 'register'),
|
|
|
|
(1, 'password_recover'),
|
|
|
|
)
|
|
|
|
|
2020-09-03 02:56:28 +00:00
|
|
|
|
2020-08-20 10:34:14 +00:00
|
|
|
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)
|
2020-09-03 02:56:28 +00:00
|
|
|
category = models.IntegerField(
|
|
|
|
'category', choices=VERIFY_CODE_TYPE_CHOICES, default=0)
|
2020-08-20 10:34:14 +00:00
|
|
|
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()
|
2020-08-24 14:35:47 +00:00
|
|
|
return now <= self.timeouted
|
2020-08-20 10:34:14 +00:00
|
|
|
|
2020-09-03 02:56:28 +00:00
|
|
|
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)
|
2020-09-18 06:03:50 +00:00
|
|
|
is_read = models.BooleanField('是否阅读', default=False)
|
2020-09-03 02:56:28 +00:00
|
|
|
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
|
2020-08-20 10:34:14 +00:00
|
|
|
|
|
|
|
def __str__(self):
|
2020-09-03 09:46:04 +00:00
|
|
|
return self.content + ':' + self.user.username
|
2020-09-03 02:56:28 +00:00
|
|
|
|
|
|
|
|
2020-09-18 06:03:50 +00:00
|
|
|
class Task(models.Model):
|
|
|
|
id = models.UUIDField('id', primary_key=True, default=uuid.uuid4)
|
2020-09-18 11:09:51 +00:00
|
|
|
created_by = models.ForeignKey(User, on_delete=models.CASCADE)
|
2020-09-18 06:03:50 +00:00
|
|
|
groups = models.ManyToManyField(Group)
|
|
|
|
content = models.TextField('内容', null=True, blank=True)
|
|
|
|
added = models.DateTimeField(auto_now_add=True)
|
|
|
|
updated = models.DateTimeField(auto_now=True)
|
|
|
|
|
2020-09-18 07:52:06 +00:00
|
|
|
def add_groups(self, groups):
|
|
|
|
if not len(groups):
|
|
|
|
groups = Group.objects.filter(status='1')
|
|
|
|
for g in groups:
|
|
|
|
self.groups.add(g)
|
|
|
|
|
2020-09-18 06:03:50 +00:00
|
|
|
class Meta:
|
|
|
|
ordering = ["-added"]
|
|
|
|
|
|
|
|
|
2020-09-18 07:52:57 +00:00
|
|
|
MESSAGE_TYPE_CHOICES = (
|
|
|
|
(0, 'url'),
|
|
|
|
(1, 'file'),
|
|
|
|
(2, 'picture')
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2020-09-18 06:03:50 +00:00
|
|
|
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(
|
|
|
|
'type', choices=MESSAGE_TYPE_CHOICES, default=0)
|
|
|
|
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)
|
|
|
|
|
2020-09-18 07:52:06 +00:00
|
|
|
|
2020-09-18 06:03:50 +00:00
|
|
|
TASK_RECORD_STATUS_CHOICES = (
|
|
|
|
(0, '未完成'),
|
|
|
|
(1, '完成'),
|
2020-09-03 02:56:28 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
|
2020-09-18 06:03:50 +00:00
|
|
|
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)
|
|
|
|
|
|
|
|
|
2020-09-03 02:56:28 +00:00
|
|
|
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)
|
2020-09-18 06:03:50 +00:00
|
|
|
content = models.TextField('内容', null=True, blank=True)
|
|
|
|
task = models.ForeignKey(Task, on_delete=models.CASCADE)
|
|
|
|
|
2020-09-03 02:56:28 +00:00
|
|
|
added = models.DateTimeField(auto_now_add=True)
|
|
|
|
updated = models.DateTimeField(auto_now=True)
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
ordering = ["-added"]
|
|
|
|
|
|
|
|
def __str__(self):
|
2020-09-18 11:09:51 +00:00
|
|
|
return self.send_from + ':' + self.send_toÒ
|
2020-09-03 02:56:28 +00:00
|
|
|
|
|
|
|
|
2020-09-18 06:03:50 +00:00
|
|
|
class MessageAddition(models.Model):
|
|
|
|
id = models.UUIDField('id', primary_key=True, default=uuid.uuid4)
|
|
|
|
category = models.IntegerField(
|
|
|
|
'category', choices=MESSAGE_TYPE_CHOICES, default=0)
|
|
|
|
message = models.ForeignKey(Message, on_delete=models.CASCADE)
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
abstract = True
|
|
|
|
|
|
|
|
|
|
|
|
class URLMessage(MessageAddition):
|
2020-09-03 02:56:28 +00:00
|
|
|
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)
|
|
|
|
|
|
|
|
|
2020-09-18 06:03:50 +00:00
|
|
|
class FileMessage(MessageAddition):
|
2020-09-03 02:56:28 +00:00
|
|
|
title = models.CharField('title', max_length=256, null=False)
|
2020-09-18 06:03:50 +00:00
|
|
|
file = models.CharField('file', max_length=256, null=False)
|
2020-09-03 02:56:28 +00:00
|
|
|
|
|
|
|
|
2020-09-18 06:03:50 +00:00
|
|
|
class ImageMessage(MessageAddition):
|
|
|
|
title = models.CharField('title', max_length=256, null=False)
|
|
|
|
picture = models.CharField('picture', max_length=256, null=False)
|
2020-09-03 02:56:28 +00:00
|
|
|
|
2020-09-13 06:06:58 +00:00
|
|
|
|
2020-09-18 06:03:50 +00:00
|
|
|
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)
|