[Answered ]-Deal with generated files for multiple users simultaneously

2👍

There are several ways to accomplish this. The first ones that spring to mind are, assuming you want to keep one set of results per user (i.e. the last generated)

1- Create unique names based on the user-id. This allows you to access the files without first consulting the user data in the DB.

It also has the advantage of not having to delete previous versions of the files.

2- Create unique filenames with the uuid library module

import uuid
user_filename = uuid.uuid4()
csv_filename = user_filename+'.csv'
png_filename = user_filename+'.png'

and store the user_filename in the DB user record for later access.

3- Do the same but using a timestamp with enough resolution

Alternatively you can create a subdirectory with a unique name and store the files inside it with a static name for both.

Options 2 and 3 require you to remove previous versions of the files when generating new ones for the same user.

As mentioned by @Wtower, store the files in the MEDIA directory, maybe under a further subdirectory.

Leave a comment