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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T08:01:42+00:00 2026-05-28T08:01:42+00:00

How do I further reduce a SearchQuerySet based on a common M2M attribute such

  • 0

How do I further reduce a SearchQuerySet based on a common M2M attribute such that I can query for all objects where sky = blue?

Assign ObjectA:

 Property → property_definition = "sky" value = "blue"
 Property → property_definition = "current_color" value = "red"

Assign ObjectB:

 Property → property_definition = "sky" value = "red"
 Property → property_definition = "current_color" value = "blue"

This should result in one and only one answer (ObjectA) but I’m getting 2 because the templates are seeing both properties.

Can anyone shed some light as to how to narrow these results. Because SearchQuerySet doesn’t suppport remove() I can’t post process them and I can’t think of a clean way to do this??

Help Please!!

--- models.py ---

DATA_CHOICES = ((u'string', u'string'), (u'integer', u'integer'),                (u'real', u'real'), (u'boolean', u'boolean'))


class PropertyDefinition(models.Model):
    name = models.CharField(unique=True, max_length=255)
    datatype = models.CharField(max_length=24, choices=DATA_CHOICES)

class Property(models.Model):
    property_definition = models.ForeignKey(PropertyDefinition)
    value = models.CharField(max_length=255)

class ObjectA(models.Model):
    properties = model.ManyToManyField(Property)
    name = models.CharField(unique=True, max_length=255)

class ObjectB(models.Model):
    properties = model.ManyToManyField(Property)
    name = models.CharField(unique=True, max_length=255)


--- search_indexes.py ---
class ObjectAIndex(indexes.BasicSearchIndex, indexes.Indexable):   
    text = indexes.CharField(document=True, use_template=True)
    name = indexes.CharField(model_attr='name')

    def get_model(self):
        return ObjectA

class ObjectBIndex(ObjectAIndex):
    def get_model(self):        
        return ObjectB


--templates (identical but named appropriately )--

{{object.name}}
{% for property in object.properties %}
    {{ property.property_definition.name }} {{ property.value }}
{% endfor %}

Thanks much!!

  • 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-28T08:01:42+00:00Added an answer on May 28, 2026 at 8:01 am

    first, why not

    
    class Property(models.Model):
        name = models.CharField(unique=True, max_length=255)
        value = models.CharField(max_length=255)
        datatype = models.CharField(max_length=24, choices=DATA_CHOICES)
    

    then, assuming the above model:

    
    ObjectA.objects.filter(properties__name='sky', properties__value='blue')
    

    third, your object model does not allow you to get both types of objects in the same query set. I would combine ObjectA and ObjectB into the same model.

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

Sidebar

Related Questions

This is a further question based on this answer: How can I implement a
I have a php function that I wish to reduce even further. <?='Testing'?> Is
I'm seeking further clarification after seeing What is responsible for releasing NSWindowController objects? I'm
Taking shs's question a step further... Why isn't all government sponsored software open source?
I have a long, lazy sequence that I want to reduce and test lazily.
I'm trying to write a custom search that will search all categories and individual
I was trying to further reduce the filesize of a SWF file by optimizing
I need a little assistance developing an algorithm that merges Lists of Lists based
let us assume that I have a reusable business layer that further makes use
Further to my question on disabling validators using javascript - Disable ASP.NET validators with

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.