im listening to milk puzzle
This commit is contained in:
parent
658f9c844c
commit
07e37cab02
|
@ -1,5 +0,0 @@
|
|||
import forget
|
||||
|
||||
from app import db
|
||||
|
||||
db.create_all()
|
|
@ -0,0 +1,28 @@
|
|||
"""empty message
|
||||
|
||||
Revision ID: e036b007017c
|
||||
Revises: 9fab742962ef
|
||||
Create Date: 2017-08-01 22:45:28.450097
|
||||
|
||||
"""
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision = 'e036b007017c'
|
||||
down_revision = '9fab742962ef'
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
|
||||
def upgrade():
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
op.add_column('accounts', sa.Column('last_delete', sa.DateTime(), server_default='epoch', nullable=True))
|
||||
# ### end Alembic commands ###
|
||||
|
||||
|
||||
def downgrade():
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
op.drop_column('accounts', 'last_delete')
|
||||
# ### end Alembic commands ###
|
13
model.py
13
model.py
|
@ -51,18 +51,26 @@ class Account(TimestampMixin, RemoteIDMixin):
|
|||
remote_avatar_url = db.Column(db.String)
|
||||
|
||||
last_fetch = db.Column(db.DateTime, server_default='epoch')
|
||||
last_delete = db.Column(db.DateTime, server_default='epoch')
|
||||
|
||||
def touch_fetch(self):
|
||||
self.last_fetch = db.func.now()
|
||||
|
||||
@db.validates('policy_keep_younger', 'policy_delete_every')
|
||||
def validate_intervals(self, key, value):
|
||||
if not (value == timedelta(0) or value >= timedelta(minutes=1)):
|
||||
value = timedelta(minutes=1)
|
||||
return value
|
||||
|
||||
# backref: tokens
|
||||
# backref: twitter_archives
|
||||
# backref: posts
|
||||
|
||||
def __repr__(self):
|
||||
return f"<Account({self.id}, {self.remote_screen_name}, {self.remote_display_name})>"
|
||||
|
||||
def post_count(self):
|
||||
return Post.query.filter(Post.author_id == self.id).count()
|
||||
return Post.query.with_parent(self).count()
|
||||
|
||||
|
||||
class Account(Account, db.Model):
|
||||
|
@ -93,7 +101,8 @@ class Post(db.Model, TimestampMixin, RemoteIDMixin):
|
|||
body = db.Column(db.String)
|
||||
|
||||
author_id = db.Column(db.String, db.ForeignKey('accounts.id'))
|
||||
author = db.relationship(Account)
|
||||
author = db.relationship(Account,
|
||||
backref=db.backref('posts', order_by=lambda: db.desc(Post.created_at)))
|
||||
|
||||
class TwitterArchive(db.Model, TimestampMixin):
|
||||
__tablename__ = 'twitter_archives'
|
||||
|
|
Loading…
Reference in New Issue