def join_room(request, room_timestamp ): # Join room based on the timestamp of the created room if request.method == 'PUT': data = JSONParser().parse(request) room = Room.objects.filter(timestamp=room_timestamp) serializer = RoomSerializer(room, data=data) if serializer.is_valid(): serializer.save() return JsonResponse(serializer.data, status=201) return JsonResponse(serializer.errors, status=400)
def room_list(request, owner=None, member=None): # List all required room, or create a new room. if request.method == 'GET': # rooms = Room.objects.filter(owner_id=owner, member_id=member) rooms = Room.objects.all() #get all rooms lists serializer = RoomSerializer(rooms, many=True, context={'request': request}) print('----------------') print(serializer.data) return JsonResponse(serializer.data, safe=False) elif request.method == 'POST': data = JSONParser().parse(request) serializer = RoomSerializer(data=data) if serializer.is_valid(): serializer.save() return JsonResponse(serializer.data, status=201) return JsonResponse(serializer.errors, status=400)