diff --git a/polls/models.py b/polls/models.py index ba9e4a3..0747cf8 100644 --- a/polls/models.py +++ b/polls/models.py @@ -140,7 +140,7 @@ class Message(models.Model): 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) - category = models.IntegerField( + type = models.IntegerField( 'Type', choices=MESSAGE_TYPE_CHOICES, default=1) #text content = models.TextField('内容', null=True, blank=True) diff --git a/polls/views/__pycache__/message.cpython-38.pyc b/polls/views/__pycache__/message.cpython-38.pyc index a0213b4..98d24d1 100644 Binary files a/polls/views/__pycache__/message.cpython-38.pyc and b/polls/views/__pycache__/message.cpython-38.pyc differ diff --git a/polls/views/__pycache__/task.cpython-38.pyc b/polls/views/__pycache__/task.cpython-38.pyc index 6cfdf27..cea612b 100644 Binary files a/polls/views/__pycache__/task.cpython-38.pyc and b/polls/views/__pycache__/task.cpython-38.pyc differ diff --git a/polls/views/message.py b/polls/views/message.py index 5aab346..90c2e57 100644 --- a/polls/views/message.py +++ b/polls/views/message.py @@ -5,7 +5,7 @@ import datetime from polls.decorators import polls_login_required from django.core.exceptions import ObjectDoesNotExist -from polls.models import Message, NormalMessage, URLMessage +from polls.models import Message @csrf_exempt diff --git a/polls/views/task.py b/polls/views/task.py index 97e650e..2f03b5c 100644 --- a/polls/views/task.py +++ b/polls/views/task.py @@ -6,13 +6,12 @@ from channels.layers import get_channel_layer from asgiref.sync import async_to_sync from polls.decorators import polls_login_required -from polls.models import NormalMessage, Task, TaskAddition +from polls.models import Message, Task, TaskAddition from polls.tasks import process_task from django.core.exceptions import ObjectDoesNotExist from polls.utils import model_to_dict, queryset_to_list - @csrf_exempt @polls_login_required def tasks(request): @@ -45,7 +44,7 @@ def create_task(request): return JsonResponse({'status': 'error', 'message': '内容不能为空'}) groups = request.POST.getlist('groups', []) task = Task.objects.create(created_by=user, content=content) - task.add_groups(groups) + task.add_groups(groups) url = request.POST.get('url') print(groups, content, url) file = request.FILES.get('file') @@ -54,7 +53,6 @@ def create_task(request): urlAddtion = TaskAddition.objects.create( task=task, category=0, url=url) - if file: fileAddtion = TaskAddition.objects.create( task=task, category=1, file=file) @@ -63,21 +61,16 @@ def create_task(request): task=task, category=2, image=picture) for group in groups: - normalMessage = NormalMessage.objects.create(send_from_id=user.id, send_to_id=group, task=task, content=content) - # t = model_to_dict(task, ["id", "content"]) - # gs = queryset_to_list(task.groups.all(), ["id"]) - # channel_layer = get_channel_layer() - # # async_to_sync(channel_layer.send)('test_channel', {'type': 'hello'}) - # async_to_sync(channel_layer.group_send)("testroom", {"type": "update_price", "content":"helo"}) - + normalMessage = Message.objects.create( + type=0, send_from_id=user.id, send_to_id=group, task=task, content=content) return JsonResponse({'status': 'success'}) + @csrf_exempt def create_test_task(request): if request.method == 'GET': return HttpResponse(status=405) channel_layer = get_channel_layer() - async_to_sync(channel_layer.group_send)("testroom", {"type": "chat.message", "message":"helo"}) + async_to_sync(channel_layer.group_send)( + "testroom", {"type": "chat.message", "message": "helo"}) return JsonResponse({'status': 'success'}) - -