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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T05:13:11+00:00 2026-05-28T05:13:11+00:00

I am using django-haystack for search. By default it is showing oldest objects first

  • 0

I am using django-haystack for search. By default it is showing oldest objects first whereas i want to show latest on top. Can anyone guide me how can i do this?
My code sample is shown below:

search_indexes.py

class PostIndex(indexes.RealTimeSearchIndex, indexes.Indexable):
    text = indexes.CharField(document=True, use_template=True)
    title = indexes.CharField(model_attr='title')
    created = indexes.DateTimeField(model_attr='created')
 
    def get_model(self):
        return Post

    def index_queryset(self):
        return self.get_model().objects.filter(created__lte=datetime.datetime.now())

Can anyone tell me the exact file where i’ll have to make changes and what changes? Do i have to make changes to query.py file in haystack? Query.py has

 def order_by(self, *args):
        """Alters the order in which the results should appear."""
        clone = self._clone()

        for field in args:
            clone.query.add_order_by(field)
        
        return clone

How can i make changes to this to show the latest on the top?

  • 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-28T05:13:11+00:00Added an answer on May 28, 2026 at 5:13 am

    You can set order_by in your haystack_urls.py (or whatever you called it) e.g

    qs = SearchQuerySet().order_by('-created')
    
    urlpatterns = patterns('haystack.views',
        url(r'^$', SearchView(searchqueryset=qs), name='haystack_search'),
    )
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using django-haystack for a search page on my site, and I want to
I'm using django-haystack for a search page on my site. I'm basically done, but
I am using django-haystack for searching. How can i display in the template the
I'm adding search to an existing Django site, using Haystack with a Solr backend.
I am using django haystack with xapian as the backend search engine. I am
I'm implementing a search system onto my django project, using django haystack. The problem
I am using django-haystack. In the highlight haystack provides, how can i render tags
I'm using Django and Python 2.6, and I want to grow my application using
I'm using django and when users go to www.website.com/ I want to point them
I am currently using Django to construct JSON encoded objects which a retrieved using

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.