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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T13:36:57+00:00 2026-06-08T13:36:57+00:00

I have two querysets that I would like to combine and sort. Here are

  • 0

I have two querysets that I would like to combine and sort.

Here are my queries:

latestbooks = Book.objects.all().order_by('-added')
latestvideos = Video.objects.all().order_by('-added')

I would like to combine these queries and sort them prior to passing them to my template so that I can create a list that shows the latest activity on the site — whether it be a new book or new video in the order they were added in.

  • 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-08T13:37:02+00:00Added an answer on June 8, 2026 at 1:37 pm

    You can combine and sort them as lists but not as querysets. Functionality, it doesn’t matter much, but bear in mind that no further filtering will be possible.

    latestbooks = Book.objects.all().order_by('-added')
    latestvideos = Video.objects.all().order_by('-added')
    
    latest = list(latestbooks) + list(latestvideos)
    latest_sorted = sorted(latest, key=lambda x: x.added, reverse=True)
    

    UPDATE

    If you’re working with different attribute names, it’s still possible, but it starts to get ugly, and this is probably not workable for more than just two variations:

    sorted(latest, key=lambda x: x.added if hasattr(x, 'added') else x.desadded, reverse=True)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

For example, let's assume that i have two QuerySEt objects: queryset1 = my_model1.objects.all().order_by('-created') queryset2
I have two querysets: category_list_avg =Category.objects.filter(operation__date__gte = year_ago).annotate(podsuma = Sum('operation__value')) category_list = Category.objects.annotate(suma =
If I were to have two different QuerySets in Django, both representing a ManyToMany
I have an Address model that contains two float fields, lat and lng .
I have a model called Story that has two integer fields called views and
I have for two similar models with one common Manager, that returns queryset for
I have two QuerySets both containing the instances of the same model class. class
I have two models Category and Entry . There is another model ExtEntry that
I have two SQL queries with about 2-3 INNER JOINS each. I need to
I have two models that are linked by another model through a many to

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.