django changing boolean field from view

# Import necessary modules
from django.shortcuts import get_object_or_404
from django.http import HttpResponse

# Retrieve the object for which the boolean field needs to be changed
def change_boolean_field(request, model_id):
    # Replace 'YourModel' with the actual name of your model
    obj = get_object_or_404(YourModel, pk=model_id)

    # Access the boolean field and toggle its value
    obj.your_boolean_field = not obj.your_boolean_field

    # Save the changes to the object

    # Return a response, indicating the success of the operation
    return HttpResponse("Boolean field updated successfully.")