将JavaScript GeoLocation数据保存到Django管理页面

时间:2016-04-07 16:27:21

标签: javascript python django

我的Home.html看起来像:

LSSerializer

当我点击按钮时,我获得了经度和经度,但我需要将其保存为Django管理页面中的元组。

到目前为止我的工作:

models.py

<!DOCTYPE html>
<html>

{{ form_.as_p }}

<body>

<p>Click the button to get your coordinates.</p>

<button onclick="getLocation()">Try It</button>
<button>Submit</button>
<p id="demo"></p>

<script>
var x = document.getElementById("demo");

function getLocation() {
    if (navigator.geolocation) {
        navigator.geolocation.getCurrentPosition(showPosition);
    } else { 
        x.innerHTML = "Geolocation is not supported by this browser.";
    }
}

function showPosition(position) {
    x.innerHTML = "Latitude: " + position.coords.latitude + 
    "<br>Longitude: " + position.coords.longitude;  
}
</script>

</body>
</html>

views.py

class SignUp(models.Model):
email = models.EmailField()
full_name = models.CharField(max_length=100, blank=True, null=True)
latitude = models.FloatField(blank=False, null=False)
longitude = models.FloatField(blank=False, null=False)
timestamp = models.DateTimeField(auto_now_add=True, auto_now=False)
updated = models.DateTimeField(auto_now_add=False, auto_now=True)

def __unicode__(self):
    return self.full_name

admin.py

def home(request):
    form_ = SignUpForm()
    context = {
        'title' : "Mayur",
        'form_' : form_
    }
return render(request, "home.html", context)

如何将位置输入Django管理面板?

0 个答案:

没有答案