Exemplo n.º 1
0
 def delete(self, request):
     data = json.loads(request.body)
     form = Blog_Form(data)
     if data.get('id') != None:
         post = get_object_or_404(Blog, pk=data['id'])
         form = Blog_Form(data, instance=post)
     if form.is_valid():
         blog = form.delete(commit=False)
         blog.delete()
         return success_message()
     else:
         print(errors_message(form))
         return errors_message(form)
Exemplo n.º 2
0
 def post(self, request):
     data = json.loads(request.body)
     form = Menu_Form(data)
     if data.get('id') != None:
         post = get_object_or_404(Menu, pk=data['id'])
         form = Menu_Form(data, instance=post)
     if form.is_valid():
         menu = form.save(commit=False)
         menu.save()
         return success_message()
     else:
         print(errors_message(form))
         return errors_message(form)
Exemplo n.º 3
0
def SaveMenu2(request):
    form = Menu_Form(request.JSON)
    if request.method == 'POST':
        if request.JSON.get('id') != None:
            post = get_object_or_404(Menu, pk=request.JSON['id'])
            form = Menu_Form(request.JSON, instance=post)
        if form.is_valid():
            menu = form.save(commit=False)
            menu.save()
            return success_message()
        else:
            print(errors_message(form))
            return errors_message(form)
    elif request.method == 'DELETE':
        if form.is_valid():
            menu = form.delete(commit=False)
            menu.delete()
            return success_message()
        else:
            print(errors_message(form))
            return errors_message(form)
    else:
        return errors_message(form)