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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T09:26:42+00:00 2026-06-17T09:26:42+00:00

The system I’m building has smart groups. By smart groups, I mean groups that

  • 0

The system I’m building has smart groups. By smart groups, I mean groups that update automatically based on these rules:

  1. Include all people that are associated with a given client.
  2. Include all people that are associated with a given client and have these occupations.
  3. Include a specific person (i.e., by ID)

Each smart groups can combine any number of these rules. So, for example, a specific smart list might have these specific rules:

  1. Include all people that are associated with client 1
  2. Include all people that are associated with client 5
  3. Include person 6
  4. Include all people associated with client 10, and who have occupations 2, 6, and 9

These rules are OR’ed together to form the group. I’m trying to think about how to best store this in the database given that, in addition to supporting these rules, I’d like to be able to add other rules in the future without too much pain.

The solution I have in mind is to have a separate model for each rule type. The model would have a method on it that returns a queryset that can be combined with other rules’ querysets to, ultimately, come up with a list of people. The one downside of this that I can see is that each rule would have its own database table. Should I be concerned about this? Is there, perhaps, a better way to store this information?

  • 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-17T09:26:42+00:00Added an answer on June 17, 2026 at 9:26 am

    Here are the models we implemented to deal with this scenario.

    class ConsortiumRule(OrganizationModel):
        BY_EMPLOYEE = 1
        BY_CLIENT = 2
        BY_OCCUPATION = 3
        BY_CLASSIFICATION = 4
        TYPES = (
            (BY_EMPLOYEE, 'Include a specific employee'),
            (BY_CLIENT, 'Include all employees of a specific client'),
            (BY_OCCUPATION, 'Include all employees of a speciified  client ' + \
                'that have the specified occupation'),
            (BY_CLASSIFICATION, 'Include all employees of a specified client ' + \
                'that have the specified classifications'))
    
        consortium = models.ForeignKey(Consortium, related_name='rules')
        type = models.PositiveIntegerField(choices=TYPES, default=BY_CLIENT)
        negate_rule = models.BooleanField(default=False,
            help_text='Exclude people who match this rule')
    
    
    class ConsortiumRuleParameter(OrganizationModel):
        """ example usage: two of these objects one with "occupation=5" one
        with "occupation=6" - both FK linked to a single Rule
        """
    
        rule = models.ForeignKey(ConsortiumRule, related_name='parameters')
        key = models.CharField(max_length=100, blank=False)
        value = models.CharField(max_length=100, blank=False)
    

    At first I was resistant to this solution as I didn’t like the idea of storing references to other objects in a CharField (CharField was selected, because it is the most versatile. Later on, we might have a rule that matches any person whose first name starts with ‘Jo’). However, I think this is the best solution for storing this kind of mapping in a relational database. One reason this is a good approach is that it’s relatively easy to clean hanging references. For example, if a company is deleted, we only have to do:

    ConsortiumRuleParameter.objects.filter(key='company', value=str(pk)).delete()
    

    If the parameters were stored as serialized objects (e.g., Q objects as suggested in a comment), this would be a lot more difficult and time consuming.

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

Sidebar

Related Questions

System.Web.Mvc has an HtmlHelper that contains a method called EditorFor that renders the editing
System.Windows.Forms.ComboBox has two different events that the programmer can handle: SelectionChangeCommitted - event fires
System.Diagnostics.Trace , System.Diagnostics.EventLog , and System.Console all seem to be unavailable. Does WinRT include
System.setProperty(file.encoding, utf-8); The comment below implies that file.encoding would be changed for all apps
System.Type contains an UnderlyingSystemType property. MSDN states that it: Indicates the type provided by
System.Collections.Queue class has Queue.Synchronized method which returns a thread-safe Queue implementation. But the generic
I've got a string that has curly quotes in it. I'd like to replace
System.Collections.Specialized.NameObjectCollectionBase has two similar properties: string[] AllKeys NameObjectCollectionBase.KeyCollection Keys Do they provide different sets
System Info: Mac OS x 10.7 CGAL installed in: CGAL INCLUDES are in /opt/local/include/CGAL/
System is: SQL Server 2008-R2 I have a table that one of its column

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.