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

  • Home
  • SEARCH
  • 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 4013198
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T09:20:29+00:00 2026-05-20T09:20:29+00:00

I have three tables, 1-Users, 2-Softwares, 3-UserSoftwares. if suppose, Users table having 6 user

  • 0

I have three tables, 1-Users, 2-Softwares, 3-UserSoftwares.

if suppose, Users table having 6 user records(say U1,U2,…,U6) and Softwares table having 4 different softwares(say S1,S2,S3,S4) and UserSoftwares stores the references if a user requested for given software only.
For example: UserSoftwares(5 records) have only two columns(userid, softwareid) which references others. and the data is:

U1 S1

U2 S2

U2 S3

U3 S3

U4 S1

Now I m expecting following results:(if current login user is U2):


S1 Disable

S2 Enable

S3 Enable

S4 Disable

Here, 1st column is softwareid or name and 2nd column is status which having only two values(Enable/Disable) based on UserSoftwares table(model). Note status is not a field of any model(table).
“My Logic is:
1. loop through each software in softwares model
2. find softwareid with current login userid (U2) in UserSoftwares model:
if it found then set status=’Enable’
if not found then set status=’Disable’
3. add this status property to software object.
4. repeat this procedure for all softwares.
”
What should be the query in python google app engine to achieve above result?

  • 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-05-20T09:20:30+00:00Added an answer on May 20, 2026 at 9:20 am

    since GAE’s datastore is not relational you have to model your many-to-many relationship without using joins. Here are two methods you can adapt easily to your needs.

    Working example using link model method (UPDATE #1)

    from google.appengine.ext import db
    
    # Defining models
    
    class User(db.Model):
        name = db.StringProperty()
    
    
    class Software(db.Model):
        name = db.StringProperty()
        description = db.TextProperty()
    
    
    class UserSoftwares(db.Model):
        user = db.ReferenceProperty(User, collection_name='users')
        software = db.ReferenceProperty(Software, collection_name='softwares')
    
    # Creating users
    
    u1 = User(name='John Doe')
    u2 = User(name='Jane Doe')
    
    # Creating softwares    
    sw1 = Software(name='Office 2007')
    sw2 = Software(name='Google Chrome')
    sw3 = Software(name='Notepad ++')
    
    # Batch saving entities
    db.put([u1, u2, sw1, sw2, sw3])
    
    """
    Creating relationship between users and softwares;
    in this example John Doe's softwares are 'Office 2007' and
    'Notepad++' while Jane Doe only uses 'Google Chrome'.
    """
    u1_sw1 = UserSoftwares(user=u1, software=sw1)
    u1_sw3 = UserSoftwares(user=u1, software=sw3)
    u2_sw2 = UserSoftwares(user=u2, software=sw2)
    
    # Batch saving relationships
    db.put([u1_sw1, u1_sw3, u2_sw2])
    
    """
    Selects all softwares.
    """
    
    rs1 = Software.all()
    
    # Print results
    print ("SELECT * FROM Software")
    for sw in rs1:
        print sw.name
    
    """
    Selects a software given it's name.
    """
    
    rs2 = Software.all().filter("name =", "Notepad ++")
    
    # Print result
    print("""SELECT * FROM Software WHERE name = ?""")
    print rs2.get().name
    
    """
    Selects all software used by 'John Smith'.
    """
    
    # Get John Doe's key only, no need to fetch the entire entity
    user_key = db.Query(User, keys_only=True).filter("name =", "John Doe").get()
    
    # Get John Doe's software list
    rs3 = UserSoftwares.all().filter('user', user_key)
    
    # Print results
    print ("John Doe's software:")
    for item in rs3:
        print item.software.name
    
    """
    Selects all users using the software 'Office 2007'
    """
    
    # Get Google Chrome's key
    sw_key = db.Query(Software, keys_only=True).filter("name =", "Google Chrome").get()
    
    # Get Google Chrome's user list
    rs4 = UserSoftwares.all().filter('software', sw_key)
    
    # Print results
    print ("Google Chrome is currently used by:")
    for item in rs4:
        print item.user.name
    

    Link model method (recommended)

    You can model a many-to-many relationship by representing each table in this way:

    from google.appengine.ext import db    
    
    class User(db.Model):
        name = db.StringProperty()
    
    
    class Software(db.Model):
        name = db.StringProperty()
        description = db.TextProperty()
    
    
    class UserSoftwares(db.Model):
        user = db.ReferenceProperty(User, collection_name='users')
        software = db.ReferenceProperty(Software, collection_name='softwares')
    

    As you can see it is quite similiar to the relational’s way of thinking.

    Key list method (alternative)

    Relationships can also be modelled as list of keys:

    class User(db.Model):
        name = db.StringProperty()
        softwares = db.ListProperty(db.Key)
    
    
    class Software(db.Model):
        name = db.StringProperty()
        description = db.TextProperty()
    
        @property
        def users(self):
            return User.all().filter('softwares', self.key())
    

    This approach is more suited for a small number of keys since it uses a ListProperty but is faster than than the link model method above.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Suppose I have three tables: user , group and xref , a table that
I have a table with three columns: user varchar, status varchar , rep int
I have three tables in the many-to-many format. I.e, table A, B, and AB
I have three tables called: users , facilities , and staff_facilities . users contains
I have a table of users profiles. Every user can have many profiles and
I have three tables: users, events, and user_events, then I do the following in
I have three tables one of this storing users basic information, the other one
I have three tables: page, attachment, page-attachment I have data like this: page ID
I have three tables tag , page , pagetag With the data below page
I have three tables like that: Articles IdArticle Title Content Tags IdTag TagName ContentTag

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.