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

  • Home
  • SEARCH
  • 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 4027772
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T11:08:18+00:00 2026-05-20T11:08:18+00:00

Sorry for probably simple question but I’m a newby in Django and really confused.

  • 0

Sorry for probably simple question but I’m a newby in Django and really confused.

I have an ugly legacy tables that I can not change.
It has 2 tables:

class Salespersons(models.Model):
    id = models.IntegerField(unique=True, primary_key=True)
    xsin = models.IntegerField()
    name = models.CharField(max_length=200)
    surname = models.CharField(max_length=200)

class Store(models.Model):
    id = models.IntegerField(unique=True, primary_key=True)
    xsin = models.IntegerField()
    brand = models.CharField(max_length=200)

So I suppose I can not add Foreign keys in class definitions because they change the tables.

I need to execute such sql request:

SELECT * FROM Salespersons, Store INNER JOIN Store ON (Salespersons.xsin = Store.xsin);

How can I achieve it using Django ORM?
Or I’m allowed to get Salespersons and Store separately i.e.

stores = Store.objects.filter(xsin = 1000)
salespersons = Salespersons.objects.filter(xsin = 1000)
  • 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-20T11:08:19+00:00Added an answer on May 20, 2026 at 11:08 am

    Given your example query, are your tables actually named Salespersons/Store?
    Anyway, something like this should work:

    results = Salespersons.objects.extra(tables=["Store"],
                              where=["""Salespersons.xsin = Store.xsin"""])
    

    However, given the names of the tables/models it doesn’t seem to me that an inner join would be logically correct. Unless you always have just 1 salesperson per store with same xsin.

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

Sidebar

Related Questions

This is probably a simple question that I am just missing but I have
Hey guys, sorry for this probably fairly simple question but I'm starting to get
Sorry for really simple question, but I wasnt able to find anything in the
Sorry for asking what is probably a very simple noob question. I have a
Im sorry for this probably dumm question, but I want to simply open modals
My question is as above. Sorry, it's probably a duplicate but I couldn't find
Sorry for this simple question, but I can't solve it... There is an example:
sorry for the dummy question but I cannot find a simple and clean way
This is probably (hopefully) a pretty simple question, but I can't seem to get
Here's a very simple, probably duplicate (sorry - I have tried searching) shell scripting

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.