Peter Kotyczka 679d7d1b58 smc
2024-03-24 22:58:33 +01:00

38 lines
1.2 KiB
Python
Executable File

from django.shortcuts import render
from django.http import HttpResponse, JsonResponse
from migration.models import ShoppingItem
from rest_framework import viewsets
from migration.serializers import ShoppingItemSerializer
class ShoppingItemViewSet(viewsets.ModelViewSet):
queryset = ShoppingItem.objects.all()
serializer_class = ShoppingItemSerializer
def index(response):
return HttpResponse("Welcome to siMed Migration")
def migration_home(request):
if request.method == 'POST':
print('Received Data',request.POST['itemName'])
ShoppingItem.objects.create(name= request.POST['itemName'])
all_items = ShoppingItem.objects.all()
return render(request,'migration.html',{'all_items': all_items})
def api_home(request,endpoint, params={"message": "Your JSON Repsonse"}):
body = request.body
data = {}
try:
data = json.loads(body)
except:
pass
print(request.GET)
print(data)
data['params'] = dict(request.GET)
data['headers'] = dict(request.headers)
data['content_type'] = request.content_type
return JsonResponse(data)
##return JsonResponse()