2014-07-09 50 views
0

我的模型选择对象:没有FOREIGNKEY对象

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”订购

回答

1

如何选择所有没有房价的建筑?

你可以做到这一点使用isnull条件作为

Building.objects.filter(rate__isnull=True).order_by('customer__last_name') 
0

如何:

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