Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8141037
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T12:21:47+00:00 2026-06-06T12:21:47+00:00

Given a table in MySQL with rows that have a ‘Country’ field, I need

  • 0

Given a table in MySQL with rows that have a ‘Country’ field, I need to provide permissions to users. Essentially, I want to be able to say “X user has access to Germany + France + Canada” but “Y user has access to France + United States”. I think a good approach may be to use Django’s groups (ie – have 1 group per country, and add people accordingly). My problem is that I want to make sure that I am querying against a set of authorized data, for security reasons.

One approach, for example, would be to create a view im MySQL for each possible combination (Germany only, Germany + France, nearly ad infinitum) but obviously this isn’t feasible given the number of potential permutations. I could make 1 view per country, and query each one separately, but then I am putting a lot of pressure on the DB if a user is allowed access to say 20 different countries.

So, how can I efficiently and securely query this data to make 100% sure that I will only ever get back authorized data?

PS: not necessarily at the SQL level. If Django has some feature hat allows me to do this, I would be fine with that.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T12:21:49+00:00Added an answer on June 6, 2026 at 12:21 pm

    You could create a separate Country model with a many-to-many relationship to users and query across this relationship when you access models.

    class Country(models.Model):
        name = models.CharField(max_length=64)
        iso_code = models.CharField(max_length=2)
        users = models.ManyToManyField("auth.User")
    
    class MyModel(models.Model):
        country = models.ForeignKey(Country)
        ...
    
    MyModel.objects.filter(country__users=current_user)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Given that I have a table with a column of TEXT in it (MySQL
I have a mysql MyISAM table with many rows that contain information about places,
I need help in indexing in MySQL. I have a table in MySQL with
What's a good way to work with many rows in MySql, given that I
I am trying to update multiple rows on one table using MySQL. I have
Given a MySQL table of real estate data, I would like to generate a
I have 10 tables in my database(MySQL). two of them is given below tbl_state
Given the table: CREATE TABLE IF NOT EXISTS `users` ( `id` bigint(20) NOT NULL
I have several tables that get JOINed together to form a table with columns
I have a MySQL table with the following columns: id(int), date (timestamp), starttime(varchar), endtime(varchar),

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.