选择没有foreignKey对象的对象

时间:2014-07-09 07:11:00

标签: django

我的模特:

class Rate(models.Model):
    building = models.ForeignKey(Building, verbose_name="Objekt")
    year = models.IntegerField("Jahr")
    monthly_rate = models.DecimalField("Monatsrate", max_digits=8, decimal_places=2)

class Building(models.Model):
    customer = model.ForeignKey(Customer, verbose_name="Kunde")
    ...

如何选择没有费率的所有建筑物? 建筑物应按“customer__last_name”

订购

2 个答案:

答案 0 :(得分:1)

  

如何选择没有费率的所有建筑物?

您可以使用isnull条件

执行此操作
Building.objects.filter(rate__isnull=True).order_by('customer__last_name')

答案 1 :(得分:0)

怎么样:

buildings_without_rate= Building.objects.filter(rate=None).order_by(...)

相关问题