From 9e5eb88ab26996b8d45095b795b06a8e30fad18c Mon Sep 17 00:00:00 2001 From: guange <8863824@gmail.com> Date: Wed, 23 Jan 2019 15:43:23 +0800 Subject: [PATCH] 1 --- chapter2/mysite/myapp/apis.py | 10 ++++++++++ chapter2/mysite/myapp/models.py | 11 +++++++++++ chapter2/mysite/myapp/views.py | 3 +++ 3 files changed, 24 insertions(+) diff --git a/chapter2/mysite/myapp/apis.py b/chapter2/mysite/myapp/apis.py index a256d9d..c56b105 100644 --- a/chapter2/mysite/myapp/apis.py +++ b/chapter2/mysite/myapp/apis.py @@ -25,3 +25,13 @@ def news(request): response = HttpResponse(json.dumps(data, ensure_ascii=False), content_type="application/json; charset=utf-8") return response + + +def proxys(request): + _proxys = Proxys.objects.order_by('-id').all()[0:20] + datas = [] + for proxy in _proxys: + datas.append( + {"ip": proxy.ip, "port": proxy.port, "delay": proxy.checktime, "check_time": proxy.created_at} + ) + return _render_json(datas) \ No newline at end of file diff --git a/chapter2/mysite/myapp/models.py b/chapter2/mysite/myapp/models.py index 5ee9614..0071ede 100644 --- a/chapter2/mysite/myapp/models.py +++ b/chapter2/mysite/myapp/models.py @@ -67,3 +67,14 @@ class Datas(models.Model): class Meta: managed = False db_table = 'datas' + + +class Proxys(models.Model): + ip = models.CharField(max_length=100, blank=True, null=True) + port = models.IntegerField(blank=True, null=True) + checktime = models.IntegerField(blank=True, null=True) + created_at = models.DateTimeField(blank=True, null=True) + + class Meta: + managed = False + db_table = 'proxys' \ No newline at end of file diff --git a/chapter2/mysite/myapp/views.py b/chapter2/mysite/myapp/views.py index 6747cf6..2203461 100644 --- a/chapter2/mysite/myapp/views.py +++ b/chapter2/mysite/myapp/views.py @@ -48,3 +48,6 @@ def result(request): "last_month_sell": last_month_sell, "hour_sell": hour_sell, "sentiments": sentiments}) + + +