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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T23:44:47+00:00 2026-05-25T23:44:47+00:00

In my site, I have three models, organized in two apps, All this models

  • 0

In my site, I have three models, organized in two apps, All this models have a timestamp field, which defines the order of appearance in the site’s feed. Instead of creating a feed for every model and making single queries ordered by the timestamp field, I want to generate a single feed that contains all this objects, rendering each one with their corresponding template, and all of them ordered by the timestamp attribute.

My first attempt would be listing all objects and combining them in a single list and sort them within Python:

class SiteFeed(Feed):
    ...
    def items(self):
        objects = list(model1.objects.all()) + list(model2.objects.all()) + list(model3.objects.all())
        objects.sort(key=lamda obj: obj.timestamp)
        return = objects
  • 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-25T23:44:47+00:00Added an answer on May 25, 2026 at 11:44 pm

    I would return an iterator from the items method. in this case sorting and aggregation of objects can be done in a lazy manner. If you pre-sort the three collections of the objects that you want to combine before you construct the iterator, the final sorting is just a matter of choosing the next object from the right collection on each iteration. Do you see what I mean?

    for example:

    class SiteFeed(Feed):
        ...
        def items(self):
            i = model1.objects.order_by('timestamp').iterator()
            j = model2.objects.order_by('timestamp').iterator()
            k = model3.objects.order_by('timestamp').iterator()
    try: u = i.next() except StopIteration: u = None
    try: v = j.next() except StopIteration: v = None
    try: w = k.next() except StopIteration: w = None ... yield min([u,v,w], key=lambda x: x.timestamp if x else datetime.max) ... # at this point you need to reiterate the iterator # corresponding to the variable that you yielded # and yield again # so, the above code must be in some sort of a loop # until ALL iterators are exhausted

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

Sidebar

Related Questions

i have many urls(string): $one = 'http://www.site.com/first/1/two/2/three/3/number/342'; $two = '/first/1/two/2/number/32'; $three = 'site.com/first/1/three/3/number/7'; $four
I have two user models one is 1. User.rb (this is my own authentication
I have three models: class Tenant < ActiveRecord::Base has_many :sites end class Site <
I currently have a site which hosts apps and has a database of users.
I have two functions that loop through all models in a Backbone collection, and
On my site, I have three roles: Role 1 Role 2 Role 3 Role
my site has three div elements, header, content and footer. i have a picture
There have been multiple discussions on this topic in the site but I am
For our CMS we have a site manager that defines the site's tree structure
I have three relevant models: Companies, Projects, and Links, and I am trying 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.