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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T01:52:22+00:00 2026-05-20T01:52:22+00:00

I have a project and category model. I am looking to only return results

  • 0

I have a project and category model.

I am looking to only return results for the categories if they have 1 project or more…

this is what I have thus far, but it seems to return the wrong result.

def category():
    return { 'categories': Category.objects.filter(project=True).all().order_by('id')}

any ideas?

class Category(models.Model):
    title = models.CharField(max_length=30)
    slug  = models.SlugField(max_length=100, blank=True, null=True)

class Project(ImageModel):
    ...
    ...
    location = models.CharField(max_length=50, help_text='The city, town or area of the project.', null=True, blank=True)
    categories = models.ManyToManyField(Category)
    ...
    ...
  • 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-20T01:52:23+00:00Added an answer on May 20, 2026 at 1:52 am

    Category.project is a Manager.

    You can use annotations. Something like:

    Category.objects.annotate(projects=Count('project')).filter(projects__gt=1)
    

    See the docs on annotations and aggregations

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

Sidebar

Related Questions

I have a Category model, and a Project model, which contains a ForeignKey to
I have two models with managers: Category and Project. class PopulatedCategoriesManager(models.Manager): def get_query_set(self): return
I have this ViewModel to represent each Category and it's several Sub-Categories in my
good day guys! in project, among others, have models: class Category(models.Model): name = models.CharField(max_length
I have a table set up like this Project Category Date Hours Proj1 test
I have a project model and a categories model that has no relation. In
In my project I am using django-mptt for categories. My model: class Category(models.model): name
folks! I have project in cc.net and this project nay start by 3 ways
My project have no visible error but when i try to run it gives
I'm developing a rails project where I have one data model with multiple fields

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.