newmediamonitoring/polls/views/message.py

26 lines
815 B
Python
Raw Normal View History

2020-09-26 05:47:36 +00:00
from django.shortcuts import render
from django.http import HttpResponse, JsonResponse
from django.views.decorators.csrf import csrf_exempt
import datetime
from polls.decorators import polls_login_required
from django.core.exceptions import ObjectDoesNotExist
from polls.models import Message, NormalMessage, URLMessage
@csrf_exempt
@polls_login_required
def last_messages(request):
if request.method == 'POST':
return HttpResponse(status=405)
id = request.user.id
group_id = request.GET.get('group_id')
messages = Message.objects.filter(send_to_id=group_id)
results = []
for o in messages:
print(dir(o))
result = dict()
result['id'] = str(o.id)
results.append(result)
return JsonResponse({'status': 'success', 'message': results}, safe=False)