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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T16:48:30+00:00 2026-06-11T16:48:30+00:00

In a Django project as models I have something like that: class Company(models.Model): name

  • 0

In a Django project as models I have something like that:

class Company(models.Model):
    name = models.CharField(_(u"Name"), max_length=100)

INPUT_TYPES = (('U', _(u"User")), ('A', _(u"Administrator")))
class CompanyData(models.Model):
    company = models.ForeignKey(Company, related_name='data')
    input_type = models.CharField(_(u"Input type"), max_length=2,
                                  choices=INPUT_TYPES)
    active = models.BooleanField(_(u"Active"))
    datafield_1 = models.CharField(_(u"Data field 1"), max_length=100)
    datafield_2 = models.CharField(_(u"Data field 2"), max_length=100)
    datafield_3 = models.CharField(_(u"Data field 3"), max_length=100)

The company data can be entered as a user or as an administrator.

It is possible to make searches on companies. The searches can be made without dealing with the input type but I want to exclude inactive company (no matter if it was set inactive by a user or by an administrator). I have tried a query like that:

Company.objects.filter(data__data_1='query string'
                       ).exclude(Q(data__active=False))

But if one of the data input is active and match the query string it will return the company even if the other data input is inactive. I have tried to sophisticate the request by forcing the input type but I have found no manner to force Django to make two different join statements on the CompanyData table.

  • 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-11T16:48:31+00:00Added an answer on June 11, 2026 at 4:48 pm

    Congratulations, you have hit on one of the weaknesses of Django’s ORM. It is not possible to perform this sort of query with object syntax; you will need to resort to raw queries in order to accomplish this.

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

Sidebar

Related Questions

Say I have two models in my Django project. class Project(models.Model): name = models.CharField(max_length=256)
class Book(models.Model): name = models.CharField(max_length=127, blank=False) class Author(models.Model): name = models.CharField(max_length=127, blank=False) books =
I have some models, connected with GenericForeignKey : Class Main(models.Model) filed_1 = models.CharField(max_length=20) object_id
I have a django project with 2 apps like this: ## tags app, models.py
In my django project, I have 4 models that are all tied together in
I have an existing Django project that has several models using concrete inheritance of
I have set up a few models in a simple django project. When I
I have a M2M field in my django model project. In my view I
I have a django project that uses a sqlite database that can be written
I have a Django project with two models: Applicant and Client, where Client is

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.