"Mingchuan Tian" <22*3*5*[email protected]*u*e*t*u*a*e*u*a*> wrote:
> load_user() is a key function for flask_login to work. However, the return > statement "return User.query.get(int(user_id))" seems to only return a user from > User table.
> What if there are two tables that store different types of users (eg. > teachers/students)? Or, should all users be stored in the same table for it to > work?
The requirement for load_user is that it returns an object that satisfies certain
properties (or inherits from UserMixin). There is no requirement that all
possiblke returned objects come from the same table. You may take them from
several tables, However, as load_user takes a single user_id, you should make sure
that the ids in the two tables do not overlap.
There are probably better patterns you can use for this problem. For example, in
your teacher/student example, you could have a Users table (used for login) and
then a teachers table and a Students table, both with foriegn keys linkng to the
Users table. This is how inheritence is implemented in relational databases.
Note that this will be different to using python inheritence with SQL-Alchemy
models, which I wouldn't recommend.