Permalink
Browse files

set up (and use) aliases for "the" price and time fields. make the vi…

…ew per-symbol
  • Loading branch information...
stnbu committed Sep 3, 2018
1 parent 725ba0a commit a81467c8d45be9fb31901c9d05f996bbddb16968
Showing with 26 additions and 6 deletions.
  1. +2 −2 coincharts/daemon/base.py
  2. +19 −0 coincharts/models.py
  3. +1 −1 coincharts/templates/coincharts/index.html
  4. +1 −1 coincharts/urls.py
  5. +3 −2 coincharts/views.py
@@ -115,7 +115,7 @@ def fetch(self, symbol_id):
response.headers['X-RateLimit-Remaining']))
data = response.json()
# validate the FIRST date from the data returned. Not perfect, but will prevent future heartache.
self.validate_datetime_object(data[0]['time_period_end'])
self.validate_datetime_object(data[0]['time'])
return data
def get_last_date_from_store(self, symbol_id):
@@ -124,7 +124,7 @@ def get_last_date_from_store(self, symbol_id):
except db.Prices.DoesNotExist:
logging.info('No `time_period_end` value found for {}'.format(symbol_id))
return None
dt = getattr(obj, 'time_period_end')
dt = getattr(obj, 'time')
return parse_dt(dt)
def insert(self, symbol_id, data):
@@ -16,6 +16,25 @@ class Prices(models.Model):
volume_traded = models.FloatField()
trades_count = models.IntegerField()
# Since there are multiple time/price fields, we set up aliases. The `@property` decorator seems to be
# the cleanest way to do this.
@property
def price(self):
return self.price_close
@price.setter
def price(self, value):
self.price_close = value
@property
def time(self):
return self.time_period_end
@time.setter
def time(self, value):
self.time_period_start = value
def __str__(self):
class_name = self.__class__.__name__
return '{}@{}'.format(
@@ -1,6 +1,6 @@
<h3>hi, mom</h3>
{% for price in prices %}
<p>{{ price.time_period_end }}: {{ price.price_close }}</p>
<p>{{ price.time }}: {{ price.price }}</p>
{% endfor %}
<strong>DONE!</strong>
@@ -3,5 +3,5 @@
from . import views
urlpatterns = [
path('', views.index, name='index'),
path('<str:symbol_id>/', views.index, name='index'),
]
@@ -4,8 +4,9 @@
from django.http import HttpResponseRedirect
from .models import Prices
def index(request):
prices = Prices.objects.all()[:100]
def index(request, symbol_id):
prices = Prices.objects.filter(symbol_id=symbol_id)[:100]
context = {
'prices': prices,
}

0 comments on commit a81467c

Please sign in to comment.