add taskaddition
This commit is contained in:
parent
3f5928a9cf
commit
292c3ee08d
|
@ -32,6 +32,7 @@ ALLOWED_HOSTS = ['*']
|
|||
|
||||
INSTALLED_APPS = [
|
||||
'channels',
|
||||
'background_task',
|
||||
'django.contrib.admin',
|
||||
'django.contrib.auth',
|
||||
'django.contrib.contenttypes',
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
pip install -r requirements.txt
|
||||
|
||||
pip install git+https://github.com/RobWeber3/django-token.git
|
||||
|
||||
pip install git+https://github.com/arteria/django-background-tasks.git
|
||||
```
|
||||
|
||||
# migrations
|
||||
|
|
|
@ -60,6 +60,12 @@ class Task(models.Model):
|
|||
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='1')
|
||||
for g in groups:
|
||||
self.groups.add(g)
|
||||
|
||||
class Meta:
|
||||
ordering = ["-added"]
|
||||
|
||||
|
@ -75,6 +81,7 @@ class TaskAddition(models.Model):
|
|||
picture = models.ImageField(
|
||||
upload_to='task/image/%Y/%m/%d/', null=True, blank=True)
|
||||
|
||||
|
||||
TASK_RECORD_STATUS_CHOICES = (
|
||||
(0, '未完成'),
|
||||
(1, '完成'),
|
||||
|
|
|
@ -5,7 +5,7 @@ from django.forms.models import model_to_dict
|
|||
import datetime
|
||||
|
||||
from polls.decorators import polls_login_required
|
||||
from polls.models import Task
|
||||
from polls.models import Task, TaskAddition
|
||||
from django.core.exceptions import ObjectDoesNotExist
|
||||
|
||||
|
||||
|
@ -28,3 +28,27 @@ def tasks(request):
|
|||
result['added'] = o.added.strftime("%Y-%m-%d %H:%M:%S")
|
||||
results.append(result)
|
||||
return JsonResponse(results, safe=False)
|
||||
|
||||
|
||||
@csrf_exempt
|
||||
@polls_login_required
|
||||
def create_task(request):
|
||||
if request.method == 'GET':
|
||||
return HttpResponse(status=405)
|
||||
user_id = request.user.id
|
||||
content = request.POST.get('content')
|
||||
if not content:
|
||||
return JsonResponse({'status': 'error', 'message': '内容不能为空'})
|
||||
groups = request.POST.getlist('groups',[])
|
||||
task = Task.objects.create(created_by__id=user_id, content=content)
|
||||
task.add_groups(groups)
|
||||
url = request.POST.get('url')
|
||||
file = request.FILES.get('file')
|
||||
picture = request.FILES.get('picture')
|
||||
if not url:
|
||||
urlAddtion = TaskAddition.objects.create(task=task,category=0, url=url)
|
||||
if not file:
|
||||
fileAddtion = TaskAddition.objects.create(task=task,category=1, file=file)
|
||||
if not picture:
|
||||
pictureAddtion = TaskAddition.objects.create(task=task,category=2, image=picture)
|
||||
return JsonResponse({'status': 'success'})
|
Loading…
Reference in New Issue