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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T03:01:19+00:00 2026-06-14T03:01:19+00:00

I have these data models in django: class User(models.Model): type = models.CharField() class Tmp1(models.Model):

  • 0

I have these data models in django:

class User(models.Model):
     type = models.CharField()

class Tmp1(models.Model):
     var1 = models.ForeignKey(User)

class Tmp2(models.Model):
     var2 = models.ForeignKey(Tmp1)

class Tmp3(models.Model):
     user = models.ForeignKey(User)
     var3 = models.ForeignKey(Tmp2)

I want to have a Tmp3 queryset which selects instances of Tmp3 which Tmp3.var3.var2.var1.id equals Tmp3.user.id.

I know how I should do it with InnerJoin in PostgreSQL but I don’t know how to do it with Django queryset.

  • 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-14T03:01:20+00:00Added an answer on June 14, 2026 at 3:01 am

    From what I understand you want to get Tmp3 objects in which their user attribute matches the related user in the Tmp1 table (for the current Tmp3 object) – it sounds like you can make use of F expressions

    from django.db.models import F
    Tmp3.objects.filter(var3__var2__var1=F('user'))
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have these models set up in Django: class SourceBusiness(models.Model): source = models.CharField(max_length=100) ...(other
I have 2 models in my Django code: class ModelA(models.Model): name = models.CharField(max_length=255) description
I have the following model in Django: from django.db import models class User(models.Model): pen_name
I have 3 models in my django app class Company(models.Model): name = models.CharField(_(Name), max_length
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 2 django models: class Foo(models.Model): baz = models.CharField() class Bar(models.Model); foo =
I have 1 question. These are my django models.(This is just example) class Users(models.Model):
I have a models in Django that are something like this: class Classification(models.Model): name
I have 3 django models (simplified for this example): class Fighter (models.Model): name =
Concerning data binding I have these classes: public class Foo : List<Bar> { public

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.