def METHOD_NAME(request):
    try:
        new_delivered = request.POST['new_delivered'] == 'True'
        old_delivered = not new_delivered
        delivery = BalloonDelivery.objects.get(
            id=int(request.POST['id']), delivered=old_delivered
        )
    except (KeyError, BalloonDelivery.DoesNotExist):
        raise Http404
    delivery.delivered = new_delivered
    delivery.save()
    return {'result': 'ok'}