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

The Archive Base Latest Questions

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

I have django models with a manytomany connection with a through class: class userProfile(models.Model):

  • 0

I have django models with a manytomany connection with a through class:

class userProfile(models.Model):
    boughtCoupons = models.ManyToManyField(Coupon, through='UserCoupons')

class UserCoupons(models.Model):
    user = models.ForeignKey(userProfile)
    coupon = models.ForeignKey(Coupon)
    date = models.DateField()


class Coupon(models.Model):
    name = models.CharField(max_length=10)

I know how I can get each of them individually using and ID or something to filter.

But, I need to get the Through table’s value with all the user’s details (profile).

So how can I do something like a JOIN, and get a UserCoupons + userProfile pair in a single query ? ( So I can get the matching user profile without an extra 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-22T15:35:02+00:00Added an answer on May 22, 2026 at 3:35 pm

    You can query directly on UserCoupons and use select_related() to fetch also the related objects in one query:

    UserCoupons.objects.select_related().filter(**your_filters)
    

    Note that select_related() doesn’t work “backwards”. That’s why you need to use a manager of the class that defines the ForeignKey to make it work (UserCoupons in this case).

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

Sidebar

Related Questions

I have 3 django models (simplified for this example): class Fighter (models.Model): name =
I have Django application with inline in place: class Account(models.Model): ContractNum = models.PositiveIntegerField(unique=True, blank=True,
I have a django model: class Book(models.Model): [..] and I want to have the
I have the following Django 1.2 models: class Category(models.Model): name = models.CharField(max_length=255) class Article(models.Model):
I have a Django application. One of my models looks like this: class MyModel(models.Model):
I have a django app which basically is just a photo album. Right now
I am exploring Django with MySQL & have a few things that I wanted
Sorry for some crazy subj. I'd like to override django models save method and
We have a Django project which runs on Google App Engine and used db.UserProperty
I am working on a Google App Engine application and I am relatively new

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.