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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T15:38:01+00:00 2026-05-24T15:38:01+00:00

I have three models, Which has some common but not exact fields, from a

  • 0

I have three models, Which has some common but not exact fields, from a single view ex. home I am retrieving like this

interviews = Interviews.objects.all().order_by('pub_date')[:3]
publications = Publications.objects.all().order_by('pub_date')[:3]
published = Published.objects.all().order_by('pub_date')[:3]

From home view I want them to show in template in such order that all the latest/New entries associated with these models will be in top.

like if interview entry 10 is the most recent entry in these all models, then it will be first, then if the published one is second recent it will be second … etc .etc

Can any one tell me how to do 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-05-24T15:38:01+00:00Added an answer on May 24, 2026 at 3:38 pm

    Depending on your other requirements it may be a good idea to make them into sublcasses of a common superclass – containing the common elements.

    It’s hard to say if it’s valid, but if you do you can query the different types of objects separately or together by calling

    SuperClass.objects.all().order_by('-pub_date')[:9]
    

    which will render the 9 first objects regerdless of what sublcass they are. Of course assuming the superclass is named SuperClass. Of course this does not insure that there are 3 of each model.

    Another simple way of solving it – although admittedly not using a query would simply be to sort the lists.

    entries = sorted(list(interviews) + list(publications) + list(published), key=lambda x: x.pub_date, reverse=True)
    

    should work – basically turning them into lists and sorting them.

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

Sidebar

Related Questions

I have a abstract class which has some common methods for all of my
I have some inlines in one of my admin models which have default values
I have three models: class ReleaseItem < ActiveRecord::Base has_many :pack_release_items has_one :pack, :through =>
Let's assume I have a model called product. Let's assume that product has three
I have three (C++) classes: Player, Hand, and Card. Player has a member, hand,
I have models corresponding to database tables. For example, the House class has color,
I am currently involved in some interesting programming language research which has, up until
I have three models presented in a multi-model form. class Parent < ActiveRecord::Base has_many
I have a Django object called Family. Family has the variable children, which is
I have three tables: page, attachment, page-attachment I have data like this: page ID

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.