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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T05:08:54+00:00 2026-06-17T05:08:54+00:00

I am creating a site where the database model looks similar to this. class

  • 0

I am creating a site where the database model looks similar to this.

class Category(models.Model):
    name = modles.CharField(max_length=30)

class Photos(models.Model):
    name = models.CharField(max_length=30)
    category = models.ForeignKey(Category)

Now I am selecting an element from photos and storing it into cache with cache.set('object',object,timeout). Now I try to access photos.name from this cache, no queries are performed. The moment I query for photos.category it performs query. Is there any way to prevent this. I only want the id of the category, after getting the id, I can query the category cache to get the element. What is the solution to implement this. Caching this was has improved my benchmarks significantly, I am trying to get more performance out of it.

  • 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-17T05:08:55+00:00Added an answer on June 17, 2026 at 5:08 am

    If you just want the ID, you can do photos.category_id.

    You might also want to explore using select_related() to get the related category at the time when you query the original photo.

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

Sidebar

Related Questions

Have not been able to find a solution for this. models.py class Product(models.Model): prod_id
This site has been super helpful with this database i am creating for work,
I have a model and a manager as class PlaylistManager(models.Manager): def add_playlist(self, name): playlist
I'm creating new Site Definitions using this method: http://weblogs.asp.net/paulballard/archive/2007/04/09/creating-a-custom-sharepoint-2007-portal-site-definition-using-the-portalprovisioningprovider-class.aspx and when they get created,
I'm creating an site which allows users to upload photos. It's a linux server.
I am creating a site similar to reddit and hacker news that has a
I'm creating news portal site. this saves to many news.Every news has html data.
I'm using podscms for creating a database site. I would like to create two
This code was taken from ActiveRecord 2.3.14's gem class ConnectionHandler def establish_connection(name, spec) @connection_pools[name]
I have a view model class which uses UnitOfWork to some database operations like

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.