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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T11:04:59+00:00 2026-06-11T11:04:59+00:00

I have two classes: A and B. Each A has an ordered ranking of

  • 0

I have two classes: A and B. Each A has an ordered ranking of Bs, and each B has an ordered ranking of As.

My models.py:

class A(models.Model):
    name = models.CharField(max_length=200)
    ...

class B(models.Model):
    name = models.CharField(max_length=200)
    ...

class Ranking(models.Model):
    a = models.ForeignKey(A)
    b = models.ForeignKey(B)
    rankofa = models.IntegerField()
    rankofb = models.IntegerField()

Examples of what I need to do:

  • Find the number of As that a B has ranked.
  • Iterate in order through all Bs ranked by a particular A and evaluate some property of B.
  • Go to an A’s lowest-ranked B, and find the ranking given by that B to that A.

I’d like to set up the rankings as an array/list of objects (or some way that does not keep making expensive database calls), but not sure how to do this as a Django models/database solution.

Any and all thoughts appreciated.

  • 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-11T11:05:00+00:00Added an answer on June 11, 2026 at 11:05 am

    What you need is intermediary M2M relation

    class Seller(models.Model):
        name = models.CharField(max_length=200)
    
    class Customer(models.Model):
        name = models.CharField(max_length=200)
        feedbacks = models.ManyToManyField(Seller, through='Feedback', related_name='feedbacks')
    
    class Feedback(models.Model):
        seller = models.ForeignKey(Seller)
        customer = models.ForeignKey(Customer)
        seller_feedback = models.IntegerField()
        customer_feedback = models.IntegerField()
    

    Find the number of sellers customer has ranked:

    customer.feedbacks.all().count()
    

    Iterate in order through all customers ranked by a particular seller and evaluate some customer property.

    for customer in seller.feedbacks.all():
        do_something(customer)
    

    Go to an sellers’s lowest-ranked customer, and find the ranking given by that customer to that a seller.

    def lowes_feedback_response(seller):
        try:
            return models.Feedback.filter(seller=seller).order_by('-seller_feedback')[0].customer_feedback
        except models.Feedback.DoesNotExist:
            return None
    

    I didn’t evaluate the code but you get the basic idea

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

Sidebar

Related Questions

Let's say I have two classes. Each class has one parameter. Parameter of first
I have two classes, WebServiceRequest and OrderRequest. Each class has properties. OrderRequest inherits from
I need to have two classes, one class has two methods each of which
I have two classes defined in different h files and each class has some
I have two classes, Foo and Bar. Each Foo has a name and a
I have two classes that extend the activity class. Each class has it's own
I have two classes (MVC view model) which inherits from one abstract base class.
Let's say we have 3 classes: A, B and C. Each class has the
I have two classes: class Customer { public string Name { get; set; }
I have two classes: Property and PropertyValue. A property has several values where each

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.