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.