def group_list(request): """ List all gourps, or create a new group. """ if request.method == 'GET': tasks = Group.objects.all() serializer = GroupSerializer(tasks, many=True) return Response(serializer.data) elif request.method == 'POST': unique_name = request.data.get("unique_name") display_name = request.data.get("display_name") if unique_name and display_name: checkgoup = Group.objects.filter(unique_name=unique_name).first() if checkgoup: res = { "code": 400, "message": "Ops!, Unique name already exists" } return Response(data=res, status=400) else: res = { "code": 400, "message": "Ops!, Unique name and display name can't be null" } return Response(data=res, status=400) group = Group.create(unique_name, display_name) group.save() serializer = GroupSerializer(group, many=False) return JsonResponse(serializer.data, safe=False)
def group_list(request): """ List all gourps, or create a new group. """ if request.method == 'GET': tasks = Group.objects.all() serializer = GroupSerializer(tasks, many=True) return Response(serializer.data) elif request.method == 'POST': unique_name = request.data.get("unique_name") display_name = request.data.get("display_name") if unique_name and display_name: checkgoup = Group.objects.filter(unique_name=unique_name).first() if checkgoup: res = {"code": 400, "message": "Ops!, Unique name already exists"} return Response(data=res, status=400) else: res = {"code": 400, "message": "Ops!, Unique name and display name can't be null"} return Response(data=res, status=400) group = Group.create(unique_name, display_name) group.save() serializer = GroupSerializer(group, many=False) return JsonResponse(serializer.data, safe=False)
def _init_Group(self): Group.create("youku", "Youku").save() Group.create("tudou", "Tudou").save() Group.create("aiqiyi", "Aiqiyi").save()
def _init_Group(self): Group.create("source", "Source").save() Group.create("solr", "Solr").save() Group.create("other", "Other").save()