Guest User

api

a guest
Jul 7th, 2016
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.58 KB | None | 0 0
  1. class Join(APIView):
  2.  
  3. def post(self, request, format=None):
  4. #current user
  5. user = request.user
  6. try:
  7. #item to join
  8. item = Items.objects.get(id = request.POST.get("id"))
  9. except Items.DoesNotExist:
  10. data = json.dumps({'status':"Item to join not found"})
  11. return HttpResponse(
  12. data, status=404, content_type="application/json"
  13. )
  14. item.attending_with.add(user)
  15. item.save()
  16. data = json.dumps({'status':"success"})
  17. return HttpResponse(data, status=200, content_type="application/json")
Add Comment
Please, Sign In to add comment