finished the front for the task manager
This commit is contained in:
36
back/testapp/views.py
Normal file
36
back/testapp/views.py
Normal file
@@ -0,0 +1,36 @@
|
||||
from django.shortcuts import render
|
||||
from django.http import JsonResponse
|
||||
import json
|
||||
from datetime import datetime
|
||||
|
||||
from .models import Task
|
||||
# Create your views here.
|
||||
|
||||
from django.forms.models import model_to_dict
|
||||
|
||||
from rest_framework.response import Response
|
||||
from rest_framework.decorators import api_view
|
||||
|
||||
@api_view(['GET'])
|
||||
def getAllTasks(request, *args, **kwargs) :
|
||||
#data = json.loads(request.body)
|
||||
#print(data)
|
||||
#data = {"salutation":"wsh wsh "+data["name"]}
|
||||
#return JsonResponse(data)
|
||||
|
||||
query = Task.objects.all().order_by("?")
|
||||
print("query : ", query)
|
||||
data = {"data" : []}
|
||||
if query and len(query) > 0 :
|
||||
for q in query :
|
||||
sub_data = {}
|
||||
sub_data["text"] = q.task_text
|
||||
sub_data["pub date"] = q.pub_date.strftime('%m/%d/%Y at %H')
|
||||
sub_data["done"] = q.done
|
||||
|
||||
data["data"].append(sub_data)
|
||||
#equivalent à model_to_dict
|
||||
|
||||
return Response(data)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user