created_at = models.DateTimeField(auto_now_add=True, auto_now=False)
updated_at = models.DateTimeField(auto_now_add=False, auto_now=True)
My table contains the following fields:
| id | created_at | updated_at | Longitude | Latitude |
I am manually inserting some values in Longitude and Latitude column and hoping created_date and updated_date fields get updated whenever i insert new record. These record are inserted from excel sheet. Simply, I am taking the value from excel and putting into the the table using mysqldb I am able to do this without django database with the following code.
import MySQLdb #For database operations
import xlrd #For reading excel file
import time
book = xlrd.open_workbook('my_data.xlsx')
s1 = book.sheet_by_name('prasad')
db = MySQLdb.connect(host = 'localhost', user = 'root', passwd = 'lmtech123',
db = 'server_db')
cur = db.cursor()
query = "insert into eyeway_devicedata(Longitude, Latitude) values(%s, %s)"
for r in range(1,s1.nrows):
ln = str(s1.cell(r,8).value)
lt = str(s1.cell(r,7).value)
values = ln, lt
cur.execute(query, values) #insert the data into the table
db.commit()
time.sleep(5)
db.close()
But i want to load the data in django database with its datetime field facility. Is it possible? Please help.