【发布时间】:2015-11-02 20:52:37
【问题描述】:
class ProductRelation(models.Model):
product_a = models.ForeignKey('Product')
product_a_rank = models.PositiveSmallIntegerField('Position')
product_b = models.ForeignKey('Product')
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 Product 实例。我怎样才能得到这些有序的结果?product.b_products.all().order_by('product_b_rank')
和product.a_products.all().order_by('product_a_rank')
Django 1.8
【问题讨论】:
标签: python django django-models django-orm