0

If it matters, I use Flask-Security, Flask-SQLAlchemy and Flask-Admin in my application.

How should I design my application so that I can connect a row in the database with one or more files, e.g. a user to their profile pictures?

damd
  • 6,116
  • 7
  • 48
  • 77

1 Answers1

1

If only one file/picture is required, it should work by adding another column. But if you want to associate multiple files to a specific user, you can create a new table for the relations:

files table:

ID   |   USER_ID   |   FILEPATH
===================================================
1    |   1         |   somewhere/on/the/server.jpg
2    |   2         |   another/file.py
3    |   1         |   second/file/of/user/one.py

The USER_ID column is a foreign key that references to the primary key in the users table. Take a look at the docs of Flask-SQLalchemy.

user3147268
  • 1,814
  • 7
  • 26
  • 39