SHARE
TWEET

Django Tracker Python Code

a guest Mar 23rd, 2012 27 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # tracker/models.py
  2. from django.db import models
  3.  
  4. class Location(models.Model):
  5.         date = models.DateTimeField(auto_now=True, auto_now_add=True)
  6.         latitude = models.CharField(max_length=128)
  7.         longitude = models.CharField(max_length=128)
  8.         accuracy = models.CharField(max_length=128)
  9.         def __unicode__(self):
  10.                 return str(self.latitude + "," + self.longitude + "," +self.accuracy)
  11.  
  12.  
  13. # tracker/views.py
  14. from django.http import HttpResponse
  15. from django.shortcuts import render_to_response
  16. from DJANGOPROJECT.tracker.models import Location
  17.  
  18. def tracker(request, data):
  19.    latitude = request.REQUEST["latitude"]
  20.    longitude = request.REQUEST["longitude"]
  21.    accuracy = request.REQUEST["accuracy"]
  22.    newlocation = Location(latitude=latitude, longitude=longitude, accuracy=accuracy)
  23.    newlocation.save()
  24.    return HttpResponse("latitude: " + latitude + " longitude:" + longitude + " accuracy:" + accuracy, status=200, mimetype='text/plain')
  25.  
  26.  
  27. def find(request):
  28.    l = Location.objects.all().order_by("-id")[0]
  29.    print(l.date)
  30.    return render_to_response('tracker/find.html', {'latitude': l.latitude, 'longitude': l.longitude, 'date': l.date})
  31.  
  32. def plot(request):
  33.    l = Location.objects.all().order_by("-id")[:20]
  34.    centerLA = l[0].latitude
  35.    centerLO = l[0].longitude
  36.    return render_to_response('tracker/plot.html', {'locations': l, 'centerLA': centerLA, 'centerLO': centerLO })
RAW Paste Data
Top