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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T07:09:48+00:00 2026-05-29T07:09:48+00:00

I have Event model instances that can belong to one or more Organization model

  • 0

I have Event model instances that can belong to one or more Organization model instances. I’ve implemented haystack 2.0.0 to index all of my Events. Here is an example search index.

class EventIndex(indexes.SearchIndex, indexes.Indexable):

    text = indexes.CharField(document=True, use_template=True)
    organization_slug = indexes.CharField(model_attr='organization__slug',
                        weight=5.0)
    organization_name = indexes.CharField(model_attr='organization__name', 
                        weight=5.0)
    name = indexes.CharField(model_attr='name', weight=10.0)

    ....    

    def get_model(self):
        return Event

    def index_queryset(self):
        return Event.objects.filter()

My question is how do I construct a SearchQuerySet query that filters Events based on one or several Organizations. For example, I want find all Events that belong to “orgnization1” and “organization3” (where the list of organizations can be any length long)

As a Django query it might look something like this:

Event.objects.filter(organization__in=[orgnization1, organization3]).filter(...)

How do I translate this to a haystack query? This is my attempt, but I don’t really know what I’m doing…

organization_list = [organization1.slug, organization2.slug]
SearchQuerySet().filter_or(organization__contains=organization_list)

Here is an example of how my models look:

class Event(models.Model):
    name = models.CharField(max_length=64) 
    organization = models.ForeignKey('mymodule.Organization')
    ...

class Organization(models.Model):
    slug = models.SlugField(max_length=64)
    name = models.CharField(max_length=64)
    ... 

Any help is much appreciated.

  • 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-29T07:09:49+00:00Added an answer on May 29, 2026 at 7:09 am

    I think I’ve found a solution. Just sharing it. Apparently, Haystack has an object called a SQ(), which functions similar to Django’s Q() object. I found somewhere that you can invoke the add() method on Django’s Q object instances to add more query parameters. Seems to work the same way with SQ.

    from haystack.forms import SearchForm
    from haystack.query import SQ, SearchQuerySet
    from haystack.views import SearchView
    
    class CustomSerchView(SearchView):
    
    
        def __call__(self, request):
    
            self.request = request
    
            ########### Custom stuff
            user = request.user
            organization_list = [organization1.slug, organization2.slug, ....]
    
            sq = SQ()
            for slug in organization_list:
                sq.add(SQ(organization_slug=slug), SQ.OR)
            sqs = SearchQuerySet().filter(sq)        
            ##########
    
            self.form = self.build_form(form_kwargs={'searchqueryset':sqs})
            self.query = self.get_query()
            self.results = self.get_results()
            return self.create_response()
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Does jquery/javascript have any event model that you can attach to your objects? Basically
I have a model that looks like this: Performance - Location - Event -
Specifically: I have a Schedule model where a person cans schedule one event per
I have a model that looks like this: class Invite(models.Model): user = models.ForeignKey(User) event
I have a parent entity in my model Event. And two child entities: Birthday,
I have a model called Event and another called Product. An event has many
I have model: [XmlRoot(ElementName = event, IsNullable=true)] public class Event { public int id
I have a Django model with separate Datefield and Timefield for an event. Is
I have this model var Item = Backbone.Model.extend({ url: 'http://localhost/InterprisePOS/Product/loaditembycategory/Event Materials' }); var onSuccess
I have two models: class Actor(models.Model): name = models.CharField(max_length=30, unique = True) event =

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.