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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T23:22:55+00:00 2026-06-10T23:22:55+00:00

I am trying to build a Reddit or Hackernews-style community section for my website.

  • 0

I am trying to build a Reddit or Hackernews-style community section for my website. Upvotes and downvotes are already implemented as well as date and time posted. The Post model has a method that returns a score for a particular post calculated based on upvotes, downvotes, and time posted. So far so good.

Now I don’t want to have to sort all my posts every single time a user loads a page. I think the solution to this (please correct me if I’m wrong) is to run a script every few minutes that sorts all the posts by score and saves them. Then when a user tries to load the front page the view will return the first 20 posts in the list of sorted posts, if someone loads the second page the view will return the next 20 items in the list and so on.

My naive approach was to have a model that looked something like this:

class SortedPosts(models.Model):
    sortedPosts = models.ListField

And then a script to run every minute that looked like this:

from myproject.models import Post, SortedPosts
posts = Post.objects.all()
SortedPosts.sortedPosts = sorted(posts, key = lambda Post: Post.getScore())
SortedPosts.sortedPosts.save()

But alas, there is no such thing as a ListField (at least in vanilla Django.) When I search on SO, the only solution I’ve found is to serialize the list and store it in a TextField. That feels wrong. Is it?

The fact that there is no ListField in Django makes me suspect that the way I’ve set out to do this is incorrect in a more fundamental way. What would the correct way to do this be?

  • 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-10T23:22:56+00:00Added an answer on June 10, 2026 at 11:22 pm

    Actually in your particular situation the serialization/deserialization procedure
    you imagine, might take even more time than sorting the posts with each request.

    1000 objects are ridiculesly few , for a postgresql/mysql database.

    Do nothing. If the need arises, use redis.

    Either you need a caching mechanism or you don’t. In your case seems overkill.

    UPDATE:

    Good to know! What if my Post model has a rank field that is kept updated. Can I index by that field and somehow retrieve my posts in order?
    

    all django fields take the optional parameter “db_index”. If you set it to True it will
    build an index on it.

    Then I suppose you want to do something like Post.objects.order_by('-rank')

    The “-” signifies descending order. Remove it and you have ascending order.

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

Sidebar

Related Questions

I'm trying build a MVC framework, but I'm confused about manage themes. Well... I
I am trying build a DataTable one row at a time using the following
Trying to build a website where the background of the site is a video
I've been trying to build a little bot which will be using Reddit's API.
I am trying build a jQuery EasyUI datagrid or treegrid out of a large
I was trying Build For Archiving application (from Titanium Mobile) with xCode 4.4, but
I'm trying build a method which returns the shortest path from one node to
I'm trying build an App Engine connected Android application and am having some problems
Trying to build out an exception if move.UserId does not equal currentUserId then Redirect
Trying to build openssl-fips-2.0 with NDK, before I was lucky found this link and

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.