How to get destination folder path relevant to MEDIA_ROOT?

In my view I have a function that generates a file but does not return anything. I want the file to be generated in a specific folder in MEDIA_ROOT and saved in my models but I’m not sure how exactly to go about doing it. Here is the relevant section of my view:

writer = get_writer(output_format, output_dir)

This function generates a file in the stated directory. I want to save it to a specific directory relevant to my MEDIA_ROOT.

Here is the relevant section of my settings.py file:

MEDIA_URL='/media/'
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')

The destination directory, for example, can be media/destination_directory but I’m not sure how to write the path relative to MEDIA_ROOT

# Define the directory inside MEDIA_ROOT where the file should be saved
destination_directory = 'destination_directory'

# Full path construction
output_dir = os.path.join(settings.MEDIA_ROOT, destination_directory)

# Ensure the directory exists
os.makedirs(output_dir, exist_ok=True)

# Now pass this output_dir to your writer function
writer = get_writer(output_format, output_dir)