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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T19:07:20+00:00 2026-06-05T19:07:20+00:00

I have models like this: class Vendor(models.Model): title = models.CharField() class Product(models.Model): … vendor

  • 0

I have models like this:

class Vendor(models.Model):
    title = models.CharField()

class Product(models.Model):
    ...
    vendor = models.ForeignKey(Vendor, null=True, blank=True)
    stock = models.ManyToManyField(Supplier, through='Stock')

class Stock(models.Model):
    in_stock = models.BooleanField(default=True)
    supplier = models.ForeignKey('catalog.Supplier', related_name='supplier_stock')
    product = models.ForeignKey('catalog.Product', related_name='product_stock')
    priority = models.IntegerField(default=0)

I designed models like this, because one Product can be supplied by different suppliers, and I need to know, what supplier exactly has this Product in stock.

So, in my view I want to get all results in values, to reduce number of queries and some specific logic. Also it duplicates me Product row with different Stock, by in python I group them up.

In my view I use:

Product.objects.all().values(
    'id', 'title', 'vendor_code', 'vendor__title', 'price', 
    'product_stock__in_stock', 'stock__title', 'stock__id', 'stock__priority')

Because of INNER JOIN and null=True for Vendor related model, it returns me not all records for Product model. It just returns values where Vendor reference is set.

If I use ‘vendor’ instead of ‘vendor__title’ it returns me more results, than previous one, because in vendor field I can get {...'vendor': *id goes here*...} or {...'vendor': None...}, but I need the vendor__title value there. So any suggestions, how to achieve this?

Thanks in advance

  • 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-05T19:07:21+00:00Added an answer on June 5, 2026 at 7:07 pm

    Changed from vendor__title to product_stock__product__vendor__title helped me to fix my problem.

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

Sidebar

Related Questions

I have two models like this: class OptionsAndFeatures(models.Model): options = models.TextField(blank=True, null=True) entertainment =
I have multiple models like this: class Model1(models.Model): user = models.ForeignKey(User) model1_filed1 = models.CharField()
I have two models like this: class ClassA(models.Model): ida = models.AutoField(primary_key=True) classb = models.ForeignKey(ClassB)
I have models like this: class IdfPracownicy(models.Model): nazwa = models.CharField(max_length=100) class IdfPracaOpinie(models.Model): nazwa =
I have a model class like this: class Note(models.Model): author = models.ForeignKey(User, related_name='notes') content
I have a model that looks like this: class Invite(models.Model): user = models.ForeignKey(User) event
I have a model.py like this: class EventTypeCategory(models.Model): name = models.CharField(max_length=50, verbose_name=Name) user =
I have a model that is something like this: class Input(models.Model): details = models.CharField(max_length=1000)
I have two models like this: class Store(models.Model): name = models.CharField(max_length=255) class Order(models.Model): store
If I have two models like class Author(models.Model): name = models.CharField(max_length=100) title = models.CharField(max_length=3,

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.