I'm working on an application and I have multiple types of users, teams and files. 2 tables in database are users and files. A user owns a file so the files table has a foreign key field to the user_id. But the files table also has a visibility property an integer that works like permissions on Linux. For example 0x0000 where first 2 bits represents a read and write permission for a team of users and the last 2 for every user of the app, 0x000 means only the owner can read/write to/from the file. 0x1010 mean every user in the same team and every user of the app can read from the file but not write. I need to implement a query to get all the files in user's scope meaning all the files that can be written or read by a certain user. I'm not sure how to write that query, I haven't seen something similar in the Tortoise examples. The query should look something like this
all_files = FilesModel.filter(id=user.id, visibility = ...) //something like visibility & 0x0110 > 0