我有以下模特:
bootstrap-sass-loader
我需要按订单价格和出价的出价排序订单,其中状态为== BID_STATES_IN_BIDS。
我怎样才能得到这个结果?
应该如下所示:
class Order(models.Model):
price = models.DecimalField(verbose_name=_("Price"), default=0.0, decimal_places=2, max_digits=7)
...
class Bid(models.Model):
order = models.ForeignKey(Order, verbose_name=_("Order"), related_name="orders")
bid = models.DecimalField(verbose_name=_("Bid"), default=0.0, decimal_places=2, max_digits=7)
status = models.IntegerField(verbose_name=_("Status"), choices=BID_STATUSES, default=BID_STATES_IN_BIDS)
...
答案 0 :(得分:0)
orders = Order.objects.filter(bid__status=BID_STATES_IN_BIDS).order_by('price')
您可以在Source
找到有关反向查找的信息答案 1 :(得分:0)