Django transactions are not working in my case

I made the following changes in my

#Imported the references

from django.db import transaction

class Project_Create(generics.CreateAPIView):
    #Added decorator
    def create(self, request, *args, **kwargs):
            project_instance = Project.objects.create(
                planner=loggedin_user, project_name=project_name)
            project_instance.creator_id =

            some_condition = True

            if some_condition:
                # Return, rolling back transaction when atomic block exits
        except Exception as e:

All I want to do is, I want to roll back the transaction if there is an error. I want to delete the created project from MongoDB if there is an error. Am I missing anything? Are there any changes in a model? or or any other file?

In fact, I want to undo all the changes made in the function before the error ocurres.