Linking databases for a management system using Flask SQLAlchemy










0















I'm trying to build a very basic management system website for a hypothetical insurance agency and i just cant wrap my head around how i should organize the database to make it so i can assign users to specific policies and have the ability to update/replace the user in case there are re-arrangements within the agency so policies can be reassigned to the proper agents. This would be used to display data based on login as well. There's 3 layers that i think i need. A User table for user data, a client data/policy table to store client and policy info, and then a table for tasks that would be assigned to policies. I need multiple users to have access to a policy and then the policy should have access to 1 row in the task table. Would it just be better to have a user table and large client table with the task columns inside rather than a separate table for the tasks? I've been banging my head with this for days so if anyone can help, i greatly appreciate it.



from flask import Flask
from flask_sqlalchemy import SQLAlchemy

app = Flask(__name__)
app.config['SECRET_KEY'] = ''
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///site.db'

db = SQLAlchemy(app)


class User(db.Model):
id = db.Column(db.Integer, primary_key=True)
name = db.Column(db.String(50))
username = db.Column(db.String(50), unique=True)
password = db.Column(db.String(50))
email = db.Column(db.String(50), unique=True)

#Multiple assigned users can access
class Client(db.Model):
id = db.Column(db.Integer, primary_key=True)
name = db.Column(db.String(50))
policy_number = db.Column(db.String(50), unique = True)
expiration_date = db.Column(db.Datetime)

#Single "client" assigned to single row of tasks based on policy number
class PolicyTasks(db.Model):
id = db.Column(db.Integer, primary_key=True)
step1 = db.Column(db.String(50))
step1_completed = db.Column(db.Boolean)
step2 = db.Column(db.String(50))
step2_completed = db.Column(db.Boolean)
step3 = db.Column(db.String(50))
step3_completed = db.Column(db.Boolean)
step4 = db.Column(db.String(50))
step4_completed = db.Column(db.Boolean)
step5 = db.Column(db.String(50))
step5_completed = db.Column(db.Boolean)


I removed the code i used to attempt to create the relationships because it might honestly be more helpful to look at the base layout










share|improve this question


























    0















    I'm trying to build a very basic management system website for a hypothetical insurance agency and i just cant wrap my head around how i should organize the database to make it so i can assign users to specific policies and have the ability to update/replace the user in case there are re-arrangements within the agency so policies can be reassigned to the proper agents. This would be used to display data based on login as well. There's 3 layers that i think i need. A User table for user data, a client data/policy table to store client and policy info, and then a table for tasks that would be assigned to policies. I need multiple users to have access to a policy and then the policy should have access to 1 row in the task table. Would it just be better to have a user table and large client table with the task columns inside rather than a separate table for the tasks? I've been banging my head with this for days so if anyone can help, i greatly appreciate it.



    from flask import Flask
    from flask_sqlalchemy import SQLAlchemy

    app = Flask(__name__)
    app.config['SECRET_KEY'] = ''
    app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///site.db'

    db = SQLAlchemy(app)


    class User(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(50))
    username = db.Column(db.String(50), unique=True)
    password = db.Column(db.String(50))
    email = db.Column(db.String(50), unique=True)

    #Multiple assigned users can access
    class Client(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(50))
    policy_number = db.Column(db.String(50), unique = True)
    expiration_date = db.Column(db.Datetime)

    #Single "client" assigned to single row of tasks based on policy number
    class PolicyTasks(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    step1 = db.Column(db.String(50))
    step1_completed = db.Column(db.Boolean)
    step2 = db.Column(db.String(50))
    step2_completed = db.Column(db.Boolean)
    step3 = db.Column(db.String(50))
    step3_completed = db.Column(db.Boolean)
    step4 = db.Column(db.String(50))
    step4_completed = db.Column(db.Boolean)
    step5 = db.Column(db.String(50))
    step5_completed = db.Column(db.Boolean)


    I removed the code i used to attempt to create the relationships because it might honestly be more helpful to look at the base layout










    share|improve this question
























      0












      0








      0








      I'm trying to build a very basic management system website for a hypothetical insurance agency and i just cant wrap my head around how i should organize the database to make it so i can assign users to specific policies and have the ability to update/replace the user in case there are re-arrangements within the agency so policies can be reassigned to the proper agents. This would be used to display data based on login as well. There's 3 layers that i think i need. A User table for user data, a client data/policy table to store client and policy info, and then a table for tasks that would be assigned to policies. I need multiple users to have access to a policy and then the policy should have access to 1 row in the task table. Would it just be better to have a user table and large client table with the task columns inside rather than a separate table for the tasks? I've been banging my head with this for days so if anyone can help, i greatly appreciate it.



      from flask import Flask
      from flask_sqlalchemy import SQLAlchemy

      app = Flask(__name__)
      app.config['SECRET_KEY'] = ''
      app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///site.db'

      db = SQLAlchemy(app)


      class User(db.Model):
      id = db.Column(db.Integer, primary_key=True)
      name = db.Column(db.String(50))
      username = db.Column(db.String(50), unique=True)
      password = db.Column(db.String(50))
      email = db.Column(db.String(50), unique=True)

      #Multiple assigned users can access
      class Client(db.Model):
      id = db.Column(db.Integer, primary_key=True)
      name = db.Column(db.String(50))
      policy_number = db.Column(db.String(50), unique = True)
      expiration_date = db.Column(db.Datetime)

      #Single "client" assigned to single row of tasks based on policy number
      class PolicyTasks(db.Model):
      id = db.Column(db.Integer, primary_key=True)
      step1 = db.Column(db.String(50))
      step1_completed = db.Column(db.Boolean)
      step2 = db.Column(db.String(50))
      step2_completed = db.Column(db.Boolean)
      step3 = db.Column(db.String(50))
      step3_completed = db.Column(db.Boolean)
      step4 = db.Column(db.String(50))
      step4_completed = db.Column(db.Boolean)
      step5 = db.Column(db.String(50))
      step5_completed = db.Column(db.Boolean)


      I removed the code i used to attempt to create the relationships because it might honestly be more helpful to look at the base layout










      share|improve this question














      I'm trying to build a very basic management system website for a hypothetical insurance agency and i just cant wrap my head around how i should organize the database to make it so i can assign users to specific policies and have the ability to update/replace the user in case there are re-arrangements within the agency so policies can be reassigned to the proper agents. This would be used to display data based on login as well. There's 3 layers that i think i need. A User table for user data, a client data/policy table to store client and policy info, and then a table for tasks that would be assigned to policies. I need multiple users to have access to a policy and then the policy should have access to 1 row in the task table. Would it just be better to have a user table and large client table with the task columns inside rather than a separate table for the tasks? I've been banging my head with this for days so if anyone can help, i greatly appreciate it.



      from flask import Flask
      from flask_sqlalchemy import SQLAlchemy

      app = Flask(__name__)
      app.config['SECRET_KEY'] = ''
      app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///site.db'

      db = SQLAlchemy(app)


      class User(db.Model):
      id = db.Column(db.Integer, primary_key=True)
      name = db.Column(db.String(50))
      username = db.Column(db.String(50), unique=True)
      password = db.Column(db.String(50))
      email = db.Column(db.String(50), unique=True)

      #Multiple assigned users can access
      class Client(db.Model):
      id = db.Column(db.Integer, primary_key=True)
      name = db.Column(db.String(50))
      policy_number = db.Column(db.String(50), unique = True)
      expiration_date = db.Column(db.Datetime)

      #Single "client" assigned to single row of tasks based on policy number
      class PolicyTasks(db.Model):
      id = db.Column(db.Integer, primary_key=True)
      step1 = db.Column(db.String(50))
      step1_completed = db.Column(db.Boolean)
      step2 = db.Column(db.String(50))
      step2_completed = db.Column(db.Boolean)
      step3 = db.Column(db.String(50))
      step3_completed = db.Column(db.Boolean)
      step4 = db.Column(db.String(50))
      step4_completed = db.Column(db.Boolean)
      step5 = db.Column(db.String(50))
      step5_completed = db.Column(db.Boolean)


      I removed the code i used to attempt to create the relationships because it might honestly be more helpful to look at the base layout







      python flask flask-sqlalchemy






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 15 '18 at 5:24









      viz228viz228

      83




      83






















          1 Answer
          1






          active

          oldest

          votes


















          0














          To wrap your head around how you should organize the database to make it so you can assign users to specific policies, take a look at the docs on the Flask website. I think the second example under One-to-Many is very similar to what you're looking to do http://flask-sqlalchemy.pocoo.org/2.3/models/.



          I would recommend keeping the tables separate and not jamming it all into one. Usually that leads to a slippy slope (in my experience) with tables with too many attributes to manage.



          It can also mean slower query times because Client.query.filter_by(username='peter').first() would then always query the client data, policy data and whatever else you later on end up throwing in that table, when you may've only needed the policy data for that specific view/api route.



          This other stackoverflow post might help too:
          database design - when to split tables?






          share|improve this answer























          • Thanks for your reply. I had intended on trying to do a one to many between the user and client( or many to one im not sure because i need multiple users to have access to 1 client), and then a one to one between client and tasks. the connection between client and tasks shouldnt need to be updated or edited but the one to many would need that capability. I just dont understand how i would write the code to do that. maybe i shouldnt separate the tasks stable from client and just put the data in 1 table.

            – viz228
            Nov 15 '18 at 6:22











          • The users have access to 1 client and only 1 client? What I'm getting at is, is it one to many or many to many?

            – lieblos
            Nov 15 '18 at 6:25












          • sorry, no the users will have access to multiple clients but i want the clients to only be accessed by its assigned users. Thats why i thought one to many or many to one would work but im not actually sure it does. the client would have access to only 1 task. Hopefully you can see why im struggling to get this. Sorry if im causing any confusion, its hard for me to explain something i dont fully understand

            – viz228
            Nov 15 '18 at 6:47












          • I think the reason it is difficult to wrap your head around is because you're trying to describe a many to many relationship as one to many or many to one. What you're looking for is the many-to-many sections of that post. Many to many doesn't really work in SQL with only the two tables.

            – lieblos
            Nov 15 '18 at 20:58











          • What you'll end up with a table of all the users, a table of all the clients and table like the tags table in the example on the docs. When you want to see if a user with id=1 has access to client with id=2, then you see if there is an entry in a third lookup table where user_id=1 and client_id=2. If there is, that user has access. To give user with id=3 access to client_id=2 also, you'd just add another entry to the lookup table with user_id=3 and client_id=2. Hopefully that illustrates it ok.

            – lieblos
            Nov 15 '18 at 20:58











          Your Answer






          StackExchange.ifUsing("editor", function ()
          StackExchange.using("externalEditor", function ()
          StackExchange.using("snippets", function ()
          StackExchange.snippets.init();
          );
          );
          , "code-snippets");

          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "1"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













          draft saved

          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53312940%2flinking-databases-for-a-management-system-using-flask-sqlalchemy%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          0














          To wrap your head around how you should organize the database to make it so you can assign users to specific policies, take a look at the docs on the Flask website. I think the second example under One-to-Many is very similar to what you're looking to do http://flask-sqlalchemy.pocoo.org/2.3/models/.



          I would recommend keeping the tables separate and not jamming it all into one. Usually that leads to a slippy slope (in my experience) with tables with too many attributes to manage.



          It can also mean slower query times because Client.query.filter_by(username='peter').first() would then always query the client data, policy data and whatever else you later on end up throwing in that table, when you may've only needed the policy data for that specific view/api route.



          This other stackoverflow post might help too:
          database design - when to split tables?






          share|improve this answer























          • Thanks for your reply. I had intended on trying to do a one to many between the user and client( or many to one im not sure because i need multiple users to have access to 1 client), and then a one to one between client and tasks. the connection between client and tasks shouldnt need to be updated or edited but the one to many would need that capability. I just dont understand how i would write the code to do that. maybe i shouldnt separate the tasks stable from client and just put the data in 1 table.

            – viz228
            Nov 15 '18 at 6:22











          • The users have access to 1 client and only 1 client? What I'm getting at is, is it one to many or many to many?

            – lieblos
            Nov 15 '18 at 6:25












          • sorry, no the users will have access to multiple clients but i want the clients to only be accessed by its assigned users. Thats why i thought one to many or many to one would work but im not actually sure it does. the client would have access to only 1 task. Hopefully you can see why im struggling to get this. Sorry if im causing any confusion, its hard for me to explain something i dont fully understand

            – viz228
            Nov 15 '18 at 6:47












          • I think the reason it is difficult to wrap your head around is because you're trying to describe a many to many relationship as one to many or many to one. What you're looking for is the many-to-many sections of that post. Many to many doesn't really work in SQL with only the two tables.

            – lieblos
            Nov 15 '18 at 20:58











          • What you'll end up with a table of all the users, a table of all the clients and table like the tags table in the example on the docs. When you want to see if a user with id=1 has access to client with id=2, then you see if there is an entry in a third lookup table where user_id=1 and client_id=2. If there is, that user has access. To give user with id=3 access to client_id=2 also, you'd just add another entry to the lookup table with user_id=3 and client_id=2. Hopefully that illustrates it ok.

            – lieblos
            Nov 15 '18 at 20:58















          0














          To wrap your head around how you should organize the database to make it so you can assign users to specific policies, take a look at the docs on the Flask website. I think the second example under One-to-Many is very similar to what you're looking to do http://flask-sqlalchemy.pocoo.org/2.3/models/.



          I would recommend keeping the tables separate and not jamming it all into one. Usually that leads to a slippy slope (in my experience) with tables with too many attributes to manage.



          It can also mean slower query times because Client.query.filter_by(username='peter').first() would then always query the client data, policy data and whatever else you later on end up throwing in that table, when you may've only needed the policy data for that specific view/api route.



          This other stackoverflow post might help too:
          database design - when to split tables?






          share|improve this answer























          • Thanks for your reply. I had intended on trying to do a one to many between the user and client( or many to one im not sure because i need multiple users to have access to 1 client), and then a one to one between client and tasks. the connection between client and tasks shouldnt need to be updated or edited but the one to many would need that capability. I just dont understand how i would write the code to do that. maybe i shouldnt separate the tasks stable from client and just put the data in 1 table.

            – viz228
            Nov 15 '18 at 6:22











          • The users have access to 1 client and only 1 client? What I'm getting at is, is it one to many or many to many?

            – lieblos
            Nov 15 '18 at 6:25












          • sorry, no the users will have access to multiple clients but i want the clients to only be accessed by its assigned users. Thats why i thought one to many or many to one would work but im not actually sure it does. the client would have access to only 1 task. Hopefully you can see why im struggling to get this. Sorry if im causing any confusion, its hard for me to explain something i dont fully understand

            – viz228
            Nov 15 '18 at 6:47












          • I think the reason it is difficult to wrap your head around is because you're trying to describe a many to many relationship as one to many or many to one. What you're looking for is the many-to-many sections of that post. Many to many doesn't really work in SQL with only the two tables.

            – lieblos
            Nov 15 '18 at 20:58











          • What you'll end up with a table of all the users, a table of all the clients and table like the tags table in the example on the docs. When you want to see if a user with id=1 has access to client with id=2, then you see if there is an entry in a third lookup table where user_id=1 and client_id=2. If there is, that user has access. To give user with id=3 access to client_id=2 also, you'd just add another entry to the lookup table with user_id=3 and client_id=2. Hopefully that illustrates it ok.

            – lieblos
            Nov 15 '18 at 20:58













          0












          0








          0







          To wrap your head around how you should organize the database to make it so you can assign users to specific policies, take a look at the docs on the Flask website. I think the second example under One-to-Many is very similar to what you're looking to do http://flask-sqlalchemy.pocoo.org/2.3/models/.



          I would recommend keeping the tables separate and not jamming it all into one. Usually that leads to a slippy slope (in my experience) with tables with too many attributes to manage.



          It can also mean slower query times because Client.query.filter_by(username='peter').first() would then always query the client data, policy data and whatever else you later on end up throwing in that table, when you may've only needed the policy data for that specific view/api route.



          This other stackoverflow post might help too:
          database design - when to split tables?






          share|improve this answer













          To wrap your head around how you should organize the database to make it so you can assign users to specific policies, take a look at the docs on the Flask website. I think the second example under One-to-Many is very similar to what you're looking to do http://flask-sqlalchemy.pocoo.org/2.3/models/.



          I would recommend keeping the tables separate and not jamming it all into one. Usually that leads to a slippy slope (in my experience) with tables with too many attributes to manage.



          It can also mean slower query times because Client.query.filter_by(username='peter').first() would then always query the client data, policy data and whatever else you later on end up throwing in that table, when you may've only needed the policy data for that specific view/api route.



          This other stackoverflow post might help too:
          database design - when to split tables?







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 15 '18 at 6:00









          liebloslieblos

          1029




          1029












          • Thanks for your reply. I had intended on trying to do a one to many between the user and client( or many to one im not sure because i need multiple users to have access to 1 client), and then a one to one between client and tasks. the connection between client and tasks shouldnt need to be updated or edited but the one to many would need that capability. I just dont understand how i would write the code to do that. maybe i shouldnt separate the tasks stable from client and just put the data in 1 table.

            – viz228
            Nov 15 '18 at 6:22











          • The users have access to 1 client and only 1 client? What I'm getting at is, is it one to many or many to many?

            – lieblos
            Nov 15 '18 at 6:25












          • sorry, no the users will have access to multiple clients but i want the clients to only be accessed by its assigned users. Thats why i thought one to many or many to one would work but im not actually sure it does. the client would have access to only 1 task. Hopefully you can see why im struggling to get this. Sorry if im causing any confusion, its hard for me to explain something i dont fully understand

            – viz228
            Nov 15 '18 at 6:47












          • I think the reason it is difficult to wrap your head around is because you're trying to describe a many to many relationship as one to many or many to one. What you're looking for is the many-to-many sections of that post. Many to many doesn't really work in SQL with only the two tables.

            – lieblos
            Nov 15 '18 at 20:58











          • What you'll end up with a table of all the users, a table of all the clients and table like the tags table in the example on the docs. When you want to see if a user with id=1 has access to client with id=2, then you see if there is an entry in a third lookup table where user_id=1 and client_id=2. If there is, that user has access. To give user with id=3 access to client_id=2 also, you'd just add another entry to the lookup table with user_id=3 and client_id=2. Hopefully that illustrates it ok.

            – lieblos
            Nov 15 '18 at 20:58

















          • Thanks for your reply. I had intended on trying to do a one to many between the user and client( or many to one im not sure because i need multiple users to have access to 1 client), and then a one to one between client and tasks. the connection between client and tasks shouldnt need to be updated or edited but the one to many would need that capability. I just dont understand how i would write the code to do that. maybe i shouldnt separate the tasks stable from client and just put the data in 1 table.

            – viz228
            Nov 15 '18 at 6:22











          • The users have access to 1 client and only 1 client? What I'm getting at is, is it one to many or many to many?

            – lieblos
            Nov 15 '18 at 6:25












          • sorry, no the users will have access to multiple clients but i want the clients to only be accessed by its assigned users. Thats why i thought one to many or many to one would work but im not actually sure it does. the client would have access to only 1 task. Hopefully you can see why im struggling to get this. Sorry if im causing any confusion, its hard for me to explain something i dont fully understand

            – viz228
            Nov 15 '18 at 6:47












          • I think the reason it is difficult to wrap your head around is because you're trying to describe a many to many relationship as one to many or many to one. What you're looking for is the many-to-many sections of that post. Many to many doesn't really work in SQL with only the two tables.

            – lieblos
            Nov 15 '18 at 20:58











          • What you'll end up with a table of all the users, a table of all the clients and table like the tags table in the example on the docs. When you want to see if a user with id=1 has access to client with id=2, then you see if there is an entry in a third lookup table where user_id=1 and client_id=2. If there is, that user has access. To give user with id=3 access to client_id=2 also, you'd just add another entry to the lookup table with user_id=3 and client_id=2. Hopefully that illustrates it ok.

            – lieblos
            Nov 15 '18 at 20:58
















          Thanks for your reply. I had intended on trying to do a one to many between the user and client( or many to one im not sure because i need multiple users to have access to 1 client), and then a one to one between client and tasks. the connection between client and tasks shouldnt need to be updated or edited but the one to many would need that capability. I just dont understand how i would write the code to do that. maybe i shouldnt separate the tasks stable from client and just put the data in 1 table.

          – viz228
          Nov 15 '18 at 6:22





          Thanks for your reply. I had intended on trying to do a one to many between the user and client( or many to one im not sure because i need multiple users to have access to 1 client), and then a one to one between client and tasks. the connection between client and tasks shouldnt need to be updated or edited but the one to many would need that capability. I just dont understand how i would write the code to do that. maybe i shouldnt separate the tasks stable from client and just put the data in 1 table.

          – viz228
          Nov 15 '18 at 6:22













          The users have access to 1 client and only 1 client? What I'm getting at is, is it one to many or many to many?

          – lieblos
          Nov 15 '18 at 6:25






          The users have access to 1 client and only 1 client? What I'm getting at is, is it one to many or many to many?

          – lieblos
          Nov 15 '18 at 6:25














          sorry, no the users will have access to multiple clients but i want the clients to only be accessed by its assigned users. Thats why i thought one to many or many to one would work but im not actually sure it does. the client would have access to only 1 task. Hopefully you can see why im struggling to get this. Sorry if im causing any confusion, its hard for me to explain something i dont fully understand

          – viz228
          Nov 15 '18 at 6:47






          sorry, no the users will have access to multiple clients but i want the clients to only be accessed by its assigned users. Thats why i thought one to many or many to one would work but im not actually sure it does. the client would have access to only 1 task. Hopefully you can see why im struggling to get this. Sorry if im causing any confusion, its hard for me to explain something i dont fully understand

          – viz228
          Nov 15 '18 at 6:47














          I think the reason it is difficult to wrap your head around is because you're trying to describe a many to many relationship as one to many or many to one. What you're looking for is the many-to-many sections of that post. Many to many doesn't really work in SQL with only the two tables.

          – lieblos
          Nov 15 '18 at 20:58





          I think the reason it is difficult to wrap your head around is because you're trying to describe a many to many relationship as one to many or many to one. What you're looking for is the many-to-many sections of that post. Many to many doesn't really work in SQL with only the two tables.

          – lieblos
          Nov 15 '18 at 20:58













          What you'll end up with a table of all the users, a table of all the clients and table like the tags table in the example on the docs. When you want to see if a user with id=1 has access to client with id=2, then you see if there is an entry in a third lookup table where user_id=1 and client_id=2. If there is, that user has access. To give user with id=3 access to client_id=2 also, you'd just add another entry to the lookup table with user_id=3 and client_id=2. Hopefully that illustrates it ok.

          – lieblos
          Nov 15 '18 at 20:58





          What you'll end up with a table of all the users, a table of all the clients and table like the tags table in the example on the docs. When you want to see if a user with id=1 has access to client with id=2, then you see if there is an entry in a third lookup table where user_id=1 and client_id=2. If there is, that user has access. To give user with id=3 access to client_id=2 also, you'd just add another entry to the lookup table with user_id=3 and client_id=2. Hopefully that illustrates it ok.

          – lieblos
          Nov 15 '18 at 20:58



















          draft saved

          draft discarded
















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53312940%2flinking-databases-for-a-management-system-using-flask-sqlalchemy%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          How to how show current date and time by default on contact form 7 in WordPress without taking input from user in datetimepicker

          Syphilis

          Darth Vader #20