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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T13:22:35+00:00 2026-05-28T13:22:35+00:00

I have these models set up in Django: class SourceBusiness(models.Model): source = models.CharField(max_length=100) …(other

  • 0

I have these models set up in Django:

class SourceBusiness(models.Model):
    source = models.CharField(max_length=100)
    ...(other fields)

class ResultBusiness(models.Model):
    sourcebusiness = models.ForeignKey(SourceBusiness)
    ...(other fields)

I want to get a list of distinct sources for which objects exist in the ResultBusiness table. For example, for the following data,

a = SourceBusiness(source="A")
a1 = SourceBusiness(source="A")
b = SourceBusiness(source="B")
c = SourceBusiness(source="C")

x = ResultBusiness(sourcebusiness=a)
y = ResultBusiness(sourcebusiness=a1)
z = ResultBusiness(sourcebusiness=c)

I want to find that ResultBusinesses exist for sources a, a1 and c, and the sources for those SourceBusinesses are “A” and “C”. Ideally, I would like to get the [“A”, “C”] in one step. Is this possible with the Django QuerySet API?

If it’s not straightforward I can work around, just want to know if this can be done in one step.

EDIT: just to clarify, [“A”, “C”] is the result I want, not the input. So, not “which ResultBusiness come from SourceBusiness with source in [A,C]”, but “for all ResultBusinesses which exist, what are the distinct possible values of their parent SourceBusiness.source”

  • 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-28T13:22:36+00:00Added an answer on May 28, 2026 at 1:22 pm
    results = SourceBusiness.objects.filter(resultbusiness__isnull=False).distinct().values_list('source', flat=True)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have these Django models: class Group(models.Model): name = models.CharField(max_length=100) parent_group = models.ManyToManyField("self", blank=True)
I have the following model: from django.db import models class State(models.Model): name = models.CharField(max_length=30)
I have these 3 models in models.py class Customer(models.Model): name = models.CharField(max_length=50) .... class
I have this Django model: class Lecture(models.Model): lecture_number = models.CharField(_('lecture number'), max_length=20) title =
Here's an example: If I have these classes class Author(models.Model): name = models.CharField(max_length=45) class
in a django-tastypie app I have the following Django-models: class Car(models.Model): name=models.CharField('name',max_length=64) class CarTrack(models.Model):
I have the following models in Django 1.3: class A(models.Model): # fields class RelatedToA(models.Model):
If I have two models in Django: class Blog(models.Model): author = models.CharField() class Post(models.Model):
I have these models class User(models.Model): user_name = models.CharField() ph_number = models.CharField() class ExamPaper(models.Model):
My django model looks like this: class Entity(models.Model): name = models.CharField(max_length=40) examples = models.ManyToManyField(Example,

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.