2
我有一個djano模型:如何在Django中找到具有最小related_set的對象?
class Expiration(models.Model):
UNIT_CHOICES = (
('M', 'Month'),
('W', 'Week')
)
unit = models.CharField(max_length = 1, choices= UNIT_CHOICES)
number_of_units = models.IntegerField(default=1)
offset = models.IntegerField(default=1)
class Profile(models.Model):
name = models.CharField(default="tmp", max_length=32, blank=True)
expiration_period = models.ForeignKey(Expiration, blank=True, null=True)
我需要做的就是獲取到期的該實例具有與它一式兩份的情況下,相關的配置文件的數量最少,返回他們中的一個。或者更好地說,如果exp
是到期實例,我正在尋找最小的exp
exp.profile_set.count()
任何人有什麼想法?
完美的答案。謝謝 – Nasir 2012-03-18 16:38:51