In my django app,I need to create a mapping between a username and a filename.When a user selects a particular file ,the program would associate a mapping between that username and the filename.
To use a python dictionary,I tried as follows:
views.py
----------
uname_file_map ={}
def user_select_file(request):
filename = get_filename_from_request()
username = request.user.username
uname_file_map[username] = filename
....
def do_some_file_ops(request):
username = request.user.username
process_file_contents(uname_file_map.get(username))
...
It works without any problem when I use two browsers(chrome and firefox) , login as two different users and select two different files. What I am wondering is,will this break if many users login at the same time and select different files,since the same dictionary instance is used by all.
Is using two database tables User with a filename_id field and Filename a better solution? Or is the dictionary sufficient?
Why don’t you use a model to achieve what you are looking for ?
I think it is more “django friendly” than using a pure python solution that would need to be checked for several security issues such as concurrence as you mention.