class ProductRelation(models.Model):
product_a = models.ForeignKey('Product', related_name='c+')
product_a_rank = models.PositiveSmallIntegerField('Position')
product_b = models.ForeignKey('Product', related_name='c+')
product_b_rank = models.PositiveSmallIntegerField('Postition')
class Product(models.Model):
b_products = models.ManyToManyField('self', through=ProductRelation, symmetrical=False,
through_fields=('product_a', 'product_b'),
related_name='a_products')product.b_products.all().order_by('product_b_rank')product.a_products.all().order_by('product_a_rank')