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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T08:05:58+00:00 2026-06-18T08:05:58+00:00

I have an app where Posts are split into various categories using the django-categories

  • 0

I have an app where Posts are split into various categories using the django-categories app, using hard-linking (ForeignKey to categories.Category).

I am also using the django-voting app to allow users to vote_up or vote_down certain posts.

Now I have a view where I require the latest posts from a list of Categories (the users category whitelist) which the user has NOT voted on and they are not his own posts. How do I go about getting these posts in the most efficient manner from the DB query load perspective.

Here is my Post model:

class Post(models.Model):
    published = models.DateTimeField(default=datetime.now)
    author = models.ForeignKey(User, blank=True, null=True,
                               verbose_name='author', 
                               related_name='author_post')
    caption = models.CharField(max_length="240")
    image = models.ImageField(upload_to='user_images')
    up_votes = models.PositiveIntegerField(default=0)
    down_votes = models.PositiveIntegerField(default=0)
    category = models.ForeignKey('categories.Category')

Should I use RAW DB queries to get posts in reverse chronological order where the current logged in user hasn’t voted and they aren’t his own posts.

  • 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-18T08:05:59+00:00Added an answer on June 18, 2026 at 8:05 am

    Depends on your db. If it’s PosgtreSQL, you will be fine with subquery.

    voted_already = (Vote.objects.filter(user=…, 
                                         content_type=…)
                                 .values_list('object_id', flat=True))
    not_voted = (Post.objects.filter(category__in=…)
                             .exclude(author=…, 
                                      pk__in=voted_already)
                             .order_by('-published'))
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Facebook app which posts news from a company website to the
I have a simple web app with users and posts. I have an index
I have two domains declared in my app. class Posts { String title String
i have an app called blog and blog and Post and Categories model. url(r'^(?P<slug>[-\w]+)/$',
Does Facebook allow that user A using mobile app posts something (text, image or
When you have a partial in /app/views/posts/comments/_comment.html.erb , doing the following <%= render @post.comments
we have a code below in a client app that posts data to an
I have problems with a session variable, users log into the app and then
I have a Django website with a PostgreSQL database. There is a Django app
Context: I have an app that shows posts and comments on the home page.

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.