diff options
author | Yves Fischer <yvesf-git@xapek.org> | 2015-11-21 13:27:51 +0100 |
---|---|---|
committer | Yves Fischer <yvesf-git@xapek.org> | 2015-11-21 13:37:05 +0100 |
commit | 76b682ac3073638fda5d6caa23594dd56bf6f06d (patch) | |
tree | 0b398cf3f8ea9f95e6b9727bfb8bc639c9dc8376 /data.py | |
download | watchnews-76b682ac3073638fda5d6caa23594dd56bf6f06d.tar.gz watchnews-76b682ac3073638fda5d6caa23594dd56bf6f06d.zip |
a functional draft
Diffstat (limited to 'data.py')
-rw-r--r-- | data.py | 41 |
1 files changed, 41 insertions, 0 deletions
@@ -0,0 +1,41 @@ +import os +import datetime +import peewee as p +import re + +class SqliteDatabase(p.SqliteDatabase): + foreign_keys = True + def _add_conn_hooks(self, conn): + p.SqliteDatabase._add_conn_hooks(self, conn) + conn.execute('PRAGMA foreign_keys = ON;').fetchone() + +db = p.Proxy() + +class BaseModel(p.Model): + class Meta: + database = db + def __json__(self): + return self._data + def __repr__(self): + return "<{.__class__.__name__} {}>".format(self, " ".join( + map(lambda kv: "{0[0]}={0[1]}".format(kv), self._data.items()))) + +class Feed(BaseModel): + created_date = p.DateTimeField(default=datetime.datetime.now) + url = p.CharField(unique=True) + title = p.CharField(null=True) + +class Item(BaseModel): + created_date = p.DateTimeField(default=datetime.datetime.now) + feed = p.ForeignKeyField(Feed, related_name='items', on_delete='CASCADE') + uid = p.CharField() + title = p.CharField(null=True) + +class Version(BaseModel): + created_date = p.DateTimeField(default=datetime.datetime.now) + item = p.ForeignKeyField(Item, related_name='versions', on_delete='CASCADE') + url = p.CharField() + title = p.CharField() + authors = p.CharField() + text = p.CharField() + |