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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T10:11:38+00:00 2026-05-12T10:11:38+00:00

I have a couple of Django models set up like this: class Group(models.model): name

  • 0

I have a couple of Django models set up like this:

class Group(models.model):
    name = models.CharField(max_length=50, unique=True)

class Section(models.Model):
    name = models.CharField(max_length=50, unique=True)
    slug = models.SlugField(help_text='Auto generated')
    groups = models.ManyToManyField(Group, blank=True)

In one part of my code I need to get all of the Section objects where the groups field is empty, I can express it using raw SQL but I’d really like to use ORM code if possible. One way of writing the query in SQL is:

select * from section where id not in (select section_id from section_groups);

Is it possible to express this requirement in an ORM query?

  • 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-12T10:11:38+00:00Added an answer on May 12, 2026 at 10:11 am

    Although the SQL generated is slightly different from the sample you’re hoping:

    Section.objects.filter(groups__isnull=True)
    

    would get the job done.

    This generates the following (formatting added)

    SELECT
        "app_section"."id",
        "app_section"."name",
        "app_section"."slug"
        FROM "app_section"
        LEFT OUTER JOIN "app_section_groups" ON 
            ("app_section"."id" = "app_section_groups"."section_id")
        WHERE "app_section_groups"."group_id" IS NULL
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Using Django 1.1.1 In models.py: class Site(models.Model): name = models.CharField(max_length=50) class SiteMonth(models.Model): site =
In my Django templates, I have a couple pieces of code that are like
I've got the following model in my Django app: class Image(models.Model): image = models.ImageField(
I have couple of questions about AS3 variables handling by AVM/compiler/scope .1. This code
I have a model and I'd like to restrict access to objects based on
I have a couple of projects in Django and alternate between one and another
I have a couple of conceptual questions: regarding serving static files (media) in Django
I have a couple of simple objects that have a many-to-many relationship. Django has
I have a couple special use cases for Django admin, and I'm curious about
I'd like to love Django, but this business of static and media files in

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.