Beispiel #1
0
def detail(request, ticker):
    """
    Renders a detail view for the given stock.
    
    @renders: stocks/detail.html
    """
    if not Stock.objects.filter(ticker=ticker.upper()).exists():
        messages.add_message(request, messages.ERROR, "That's not a stock.")
        return redirect('/stocks/')
    
    stock_data = api.get_stock(ticker)
    stock_data.searched_count += 1
    stock_data.save()
    return render(request, 'stocks/detail.html', {'stock': stock_data})
 def get_random_stock(self):
     all_tickers = Stock.objects.values_list('ticker')
     random_ticker = random.choice(all_tickers)[0]
     return api.get_stock(random_ticker)