from datetime import datetime from app import app, db class Url(db.Model): id = db.Column(db.Integer, primary_key=True) url = db.Column(db.String(2000), nullable=False) hash = db.Column(db.String(20), index=True, unique=True, nullable=False) birth = db.Column(db.DateTime, default=datetime.utcnow) death = db.Column(db.DateTime) view_counter = db.Column(db.Integer) def __init__(self, **kwargs): super(Url, self).__init__(**kwargs) if not self.url.lower().startswith(('http://', 'https://')): self.url = f'https://{self.url}'