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 848933
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T07:01:15+00:00 2026-05-15T07:01:15+00:00

I have the following model structure class User(db.Model) : nickname = db.StringProperty(required=True) fullname =

  • 0

I have the following model structure

class User(db.Model) :
nickname = db.StringProperty(required=True)
fullname = db.StringProperty(required=True)

class Article(db.Model) :
title = db.StringProperty(required=True)
body = db.StringProperty(required=True)
author = db.ReferenceProperty(User, required=True)

class Favorite(db.Model) :
who = db.ReferenceProperty(User, required=True)
what = db.ReferenceProperty(Article, required=True)

I’d like to display 10 last articles according to this pattern:

article.title, article.body, article.author(nickname), info if this article has been already favorited by the signed in user.

I have added a function which I use to get the authors of these articles using only one query (it is described here)

But I don’t know what to do with the favorites (I’d like to know which of the displayed articles have been favorited by me using less than 10 queries (I want to display 10 articles)). Is it possible?

  • 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-15T07:01:16+00:00Added an answer on May 15, 2026 at 7:01 am

    You can actually do this with an amortized cost of 0 queries if you denormalize your data more! Add a favorites property to Authors which stores a list of keys of articles which the user has favorited. Then you can determine if the article is the user’s favorite by simply checking this list.

    If you retrieve this list of favorites when the user first logs in and just store it in your user’s session data (and update it when the user adds/removes a favorite), then you won’t have to query the datastore to check to see if an item is a favorite.


    Suggested update to the Authors model:

    class Authors(db.Model):  # I think this would be better named "User"
        # same properties you already had ...
        favorites = db.ListProperty(db.Key, required=True, default=[])
    

    When the user logs in, just cache their list of favorites in your session data:

    session['favs'] = user.favorites
    

    Then when you show the latest articles, you can check if they are a favorite just by seeing if each article’s key is in the favorites list you cached already (or you could dynamically query the favorites list but there is really no need to).

    favs = session['favs']
    articles = get_ten_latest_articles()
    for article in articles:
        if article.key() in favs:
            # ...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 537k
  • Answers 537k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Updating 64 UIViews at a high frequency is going to… May 17, 2026 at 1:34 am
  • Editorial Team
    Editorial Team added an answer I can think of a couple of ways to approach… May 17, 2026 at 1:34 am
  • Editorial Team
    Editorial Team added an answer I've been looking for this issue for over a week,… May 17, 2026 at 1:34 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

I have the following structure: class FeatureType(models.Model): type = models.CharField(max_length=20) def __unicode__(self): return self.type
I have the following model structure below: class Master(models.Model): name = models.CharField(max_length=50) mounting_height =
For a little background: I have a DLL project with the following structure: Rivworks.Model
I am a noob in using model/view paradigm in Qt and have the following
I have a simple model class Ad < ActiveRecord::Base has_many :ad_items end class AdItem
I'm struggling to model a particular relationship with ActiveRecord. I currently have the following
I have 3 models with the following associations. A model Question belongs to a
I have a database structure that has a Person table which contains fields such
I have a strange behaviour on my Django/PostgreSQL system. After saving a model object
I have an application which has the following characteristics There are Clubs Each Club

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.