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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T09:54:42+00:00 2026-05-26T09:54:42+00:00

My simplified models are as follows: class Function(models.Model): name = models.CharField(max_length=20) params = models.ManyToManyField(Param)

  • 0

My simplified models are as follows:

class Function(models.Model):
    name = models.CharField(max_length=20)
    params = models.ManyToManyField("Param")

class Param(models.Model):
    name = models.CharField(max_length=20)
    value = models.CharField(max_length=20)

So, every function object has the set of parameters, for example:

f = Function(name="my_function")
f.save()
param1 = Param(name="height", value="100")
param1.save()
param2 = Param(name="width", value="200")
param2.save()
f.params.add(param1)
f.params.add(param2)

The problem is that I cannot figure how to select a function using a filter on function name, parameter name and parameter value.

For above function, the select should be:

Get function with name “my_function” which contains parameter with name “height” and value “100” AND parameter with name “width” and value “200”.

Thank you in advance!

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

    This might work:

    from django.db.models import Q
    
    functions = (Function.objects
        .filter(name='my_function')
        .filter(Q(params__name='height') & Q(params__value="100")
        .filter(Q(params__name="width") & Q(params__value="200"))
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have models (simplified example): class Group(models.Model): name = models.CharField(max_length = 32) class Person(models.Model):
I have the following models (simplified): class Location(models.Model): name = models.CharField(max_length=100) is_ok = models.BooleanField()
Consider this simplified model in Django: class Item(models.Model): title = models.CharField(max_length=200) pub_date = models.DateTimeField()
I have 3 django models (simplified for this example): class Fighter (models.Model): name =
Here is a simplified version of one of my models: class ImportRule(models.Model): feed =
Lets say I have this class (simplified): class Tag (...): children = models.ManyToManyField(null=True, symmetrical=False)
I have a problem with the following (simplified version) models: Sponsor(models.Model): sponsor_name = models.CharField()
I have models that look like this (simplified of course): class Product(models.Model): product_code =
I have a following (simplified) class in models.py : class Order( models.Model ) :
Simplified example: I have an object that models a user. Users have a first

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.