7
If that is the last hour, then tiempo
should be greater than the timestamp of an hour ago. You should also calculate that in the view function, since otherwise if you later query the view, it will always return data later than an hour before you started the web server:
from datetime import datetime, timedelta
def last_hour(request):
time = datetime.now() - timedelta(hours=1)
hour = serialize('geojson',data.objects.filter(tiempo__gte=time))
return HttpResponse(hour, content_type='json')
Source:stackexchange.com