雖然這可能是基本的,但對我來說,它證明超出了我的水平。我的感謝是事先做好的。關於如何顯示需要執行計算的一行數據的建議
我想要實現的是我查詢的一行數據,在根據Liveroute表中的字段的值查詢爲非活動狀態之後,我執行計算找到兩組經度之間的距離和緯度值,我可以使用半正式公式來計算兩點經度和緯度之間的距離。但是我擔心這個計算過程可能需要一些時間,並且我無法在表格中顯示更多行數據。所以我想我會將計算結果保存在另一個表中並從該表中獲取數據並顯示它。
我將對錶中的值執行計算,使其變爲非活動狀態。 這是Django代碼,它告訴該行在Liveroute模型類中是處於活動狀態還是非活動狀態。
class LiveRoutes(models.Model):
user = models.ForeignKey(User)
route = models.ForeignKey(UserRoutes)
status = models.ForeignKey(LiveRoutesStatus)
traveller = models.ManyToManyField(LiveRouteTravellers)
datetime = models.DateTimeField()
def __unicode__(self):
return self.route.__unicode__()
def isActive(self):
utc = pytz.utc
os.environ['TZ'] = 'UTC'
local = pytz.timezone("Asia/Calcutta")
now = utc.localize(datetime.datetime.today())
now = now.astimezone(local)
time_delta = (local.localize(self.datetime.replace(tzinfo=None)) + datetime.timedelta(minutes=self.route.journey_time_day)) - now
if time_delta.days == -1 and (24 - (time_delta.seconds/3600)) <= 2:
return True
elif time_delta.days >= 0:
return True
else:
return False
基於從isActive功能這個價值,我想如下
def carbonFootPrint(request):
if request.method != "GET":
raise Http404
routes = LiveRoutes.objects.all();
routeDetailArr = []
for lroute in routes:
routeDetail = dict()
if lroute.isActive() == False:
#Now I need to find out the start location and end location for the journey and the number of travellers.
routeDetail['travellers'] = lroute.traveller.all().count()
routeDetail['start_loc_lat']= lroute.route.start_location.latitude
routeDetail['start_loc_long'] = lroute.route.start_location.longitude
routeDetail ['end_loc_lat'] = lroute.route.end_location.latitude
routeDetail['end_loc_long'] = lroute.route.end_location.longitude
routeDetail['distance'] = haversine(start_loc_lat,start_loc_long,end_loc_lat,end_loc_long)
routeDetailArr.append(routeDetail)
我的問題是如何將這些數據返回到另一臺,因此以後我可以取來執行計算那些價值。 謝謝任何意見將不勝感激。
使用的request.session – catherine 2013-02-25 09:20:22
請給我一些鏈接那個會議事情的細節。 – 2013-02-25 09:21:52
我沒有鏈接,但我可以提供樣本數據。 – catherine 2013-02-25 09:22:47