我有兩個型號如何加入兩個表的結果,Django的蟒蛇
class Weather(model.model):
region = models.ForeignKey(Region)
district = models.ForeignKey(District)
temp_max = models.IntegerField(blank=True, null=True, verbose_name='Max temperature (C)')
temp_min = models.IntegerField(blank=True, null=True, verbose_name='Min temperature (C)')
和
class Plan(model.model):
name = tinymce_models.HTMLField(blank=True, null=True)
region = models.ForeignKey(Region)
district = models.ForeignKey(District)
提供給每一個地區和地區有唯一的行。 我想要的結果結合起來,這樣我可以得到兩個表
這兩款車型都沒有相互關聯的所有列。 「 我需要讓加盟像
join weather w on w.region = A.region and w.distric = A.district
,這樣的結果包含everyobject所有列像
obj.temp_max等
如果我有多行,是否有任何方法來聚合e,g溫度。即我有兩個天氣enteries相同的地區和地區,我想avg – user825904
我也必須顯示的數據是爲計劃。所以我想從計劃走向天氣。不是從天氣到計劃。我不認爲我可以去'plan.region.weather.temp_max',因爲一個地區會有很多行,我想過濾地區和地區的聯合 – user825904