add message
This commit is contained in:
parent
edceafd88d
commit
b3679a54af
|
@ -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)
|
||||
|
|
Binary file not shown.
Binary file not shown.
|
@ -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
|
||||
|
|
|
@ -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):
|
||||
|
@ -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'})
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue