I don't know if what I am trying to do makes the most sense or if there is a better way to do this. However, I am learning how to build a website using django. I am wondering, can I use an external python script that runs daily to get stock information, and publish it to my django website database?
I have created a Stock class as follows:
class Stock(models.Model):
def __str__(self):
return self.name
name = models.CharField(max_length=50)
ticker = models.CharField(max_length=5)
price = models.DecimalField(max_digits=100, decimal_places=2)
date = models.DateField()
I then run a python script that pulls stock data down and tries to write to the database as follows:
dfDatabase = dfCurrentDay[['Ticker', 'Company', 'Close', 'Date']]
con = db.connect(r'C:\Users\shawn\Dev\stockshome\trying_django\src\db.sqlite3')
dfDatabase.to_sql('Stock', con=con, if_exists='replace')
data = con.execute("SELECT * FROM Stock").fetchall()
print(data)
When I print data, it returns the appropriate values. However, when I go to the webpage, it shows up blank. Is that because I have done something wrong with my view, or am I doing something wrong trying to write to the database?
Is there a different way I should be approaching this idea? I envision having various pages based on stock sector, or market cap sizes, etc and I'd like to have a page with a table of the stock information and then a hyperlink to another page that will show the chart, or more detailed financial data.