newmediamonitoring/polls/views/group.py

24 lines
770 B
Python
Raw Normal View History

2020-09-20 11:14:54 +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 dashboard.models import Group
@csrf_exempt
@polls_login_required
def groups(request):
if request.method == 'POST':
return HttpResponse(status=405)
id = request.user.id
groups = Group.objects.filter(status='开启')
results = []
for o in groups:
result = dict()
result['id'] = str(o.id)
result['name'] = o.name
result['image'] = request.build_absolute_uri(o.image.url)
results.append(result)
return JsonResponse(results, safe=False)