这是我的烧瓶模型(我正在使用 Flask-Sqlalchemy)。
class Feeds(db.Model):
id = db.Column(db.Integer, primary_key=True)
feed_link = db.Column(db.String(100))
url = db.Column(db.String(100))
title = db.Column(db.Text)
summary = db.Column(db.Text)
content = db.Column(db.Text)
published_date = db.Column(db.DateTime)
created_at = db.Column(db.DateTime)
def __init__(self, feed_link, url, title, summary, content, published_date):
self.feed_link = feed_link
self.url = url
self.title = title
self.summary = summary
self.content = content
self.published_date = published_date
print self.published_date
#self.created_at = datetime.utcnow()
self.created_at = date.today()
这就是我插入数据的地方。
for i in range(0,len(feed['entries'])):
post = {}
post['title'] = feed['entries'][i].title,
post['summary'] = feed['entries'][i].summary,
post['url'] = feed['entries'][i].link
post['content'] = ''
for content in feed['entries'][i]['content']:
post['content'] = post['content'] + content.value
post['published_date'] = feed['entries'][i].published_parsed
db.session.add(Feeds(feed_link=rss_link, url=post['url'], title=post['title'][0], summary=post['summary'][0],
content=post['content'], published_date=post['published_date']))
db.session.commit()
除 self.published_date 外,所有字段均已正确插入。插入时,数据存在,但检索日期字段时为 0。这里我使用 mysql 作为数据库。
有人可以告诉我,问题是什么以及如何解决?