31 lines
1.0 KiB
Python
31 lines
1.0 KiB
Python
from sqlalchemy import Column, Integer, String, Date, UniqueConstraint
|
|
|
|
from commons.models.mixin.base import BaseModelMixin
|
|
from commons.models.model import Model
|
|
from core.extensions import db
|
|
|
|
|
|
class DataGuangdong(db.Model, Model, BaseModelMixin):
|
|
__tablename__ = 'DATA_GUANGDONG'
|
|
|
|
id = Column('ID', Integer, primary_key=True)
|
|
url = Column('URL', String(512), default='', comment='下载地址')
|
|
name = Column('NAME', String(128), default='', comment='名称')
|
|
source = Column('SOURCE', String(128), default='', comment='来源')
|
|
date = Column('DATE', Date, comment='日期')
|
|
|
|
__table_args__ = (
|
|
UniqueConstraint(name, date, name='Idx_key'),
|
|
{'comment': '广东数据'},
|
|
)
|
|
|
|
def __init__(self, *args, **kwargs):
|
|
super().__init__(*args, **kwargs)
|
|
|
|
def find_by_key(self):
|
|
query = DataGuangdong.query
|
|
query = query.filter(DataGuangdong.name == self.name)
|
|
query = query.filter(DataGuangdong.date == self.date)
|
|
result = query.one_or_none()
|
|
return result
|