Example #1
0
def task_list_jsn(request):
    if request.method == 'GET':
        tasks = Task.objects.all()
        tasks = [t.to_json() for t in tasks]
        return JsonResponse(tasks, safe=False)
    elif request.method == 'POST':
        data = json.loads(request.body)
        task= Task(title=data['title'], owner=request.user,created = datetime.datetime.now()
                   ,due = datetime.datetime.now() + datetime.timedelta(days=1, hours=3), mark = False)
        task.save()
    return JsonResponse(task.to_json())
Example #2
0
def task_list(request):
    if request.method == 'GET':
        tasks = Task.objects.all()
        for task in tasks:
            task.to_json()
        return JsonResponse(Task.objects.first().to_json(), safe=False)
    elif request.method == 'POST':
        data = json.loads(request.body)
        tlist = Task(name=data['name'],
                     created=data['created'],
                     due_on=data['due_on'],
                     owner=data['owner'],
                     mark=data['mark'])
        tlist.save()
        return JsonResponse(tlist.to_json())