class Type(db.Model): __tablename__ = 'type' id = db.Column(db.Integer, primary_key=True) name = db.Column(db.String(255)) addtime = db.Column(db.DateTime) def __repr__(self): return "<id %s>" % self.id
class Admin(db.Model): __tablename__ = 'admin' id = db.Column(db.Integer, primary_key=True) username = db.Column(db.String(255)) password = db.Column(db.String(255)) face = db.Column(db.String(255)) addtime = db.Column(db.DateTime) def __repr__(self): return "<id %s>" % self.id
class Sonart(db.Model): __tablename__ = 'sonart' id = db.Column(db.Integer, primary_key=True) text = db.Column(db.String(255)) viewtime = db.Column(db.DateTime) uid = db.Column(db.Integer, db.ForeignKey('user.id')) fid = db.Column(db.Integer, db.ForeignKey('fatherart.id')) user = db.relationship('User', backref=db.backref('sonart')) fatherart = db.relationship('Fatherart', backref=db.backref('sonart')) def __repr__(self): return "<id %r>" % self.id
class Admins(db.Model): """ 관리자 테이블 """ __tablename__ = 'admins' id = db.Column(db.Integer, primary_key=True) uid = db.Column(db.Integer, db.ForeignKey('users.id'), nullable=False) created_at = db.Column(db.DateTime, nullable=False, default=datetime.datetime.now) def get_admin_object(self): admin = { 'id': self.id, 'uid': self.uid, 'created_at': str(self.created_at) } return admin
class New(db.Model): __tablename__ = 'new' id = db.Column(db.Integer, primary_key=True) title = db.Column(db.String(255)) text = db.Column(db.Text) cover = db.Column(db.String(255)) clicknum = db.Column(db.Integer) comnum = db.Column(db.Integer) createtime = db.Column(db.DateTime) altertime = db.Column(db.DateTime) uid = db.Column(db.Integer, db.ForeignKey('user.id')) tid = db.Column(db.Integer, db.ForeignKey('type.id')) user = db.relationship('User', backref=db.backref('new')) type = db.relationship('Type', backref=db.backref('new')) def __repr__(self): return "<id %r>" % self.id
class CallLogs(db.Model): """ 통화기록 테이블 """ __tablename__ = 'call_logs' id = db.Column(db.Integer, primary_key=True) uid = db.Column(db.Integer, db.ForeignKey('users.id'), nullable=False) name = db.Column(db.String(40), nullable=False) # 저장된 이름 log_type = db.Column(db.Enum('IN', 'OUT', 'MISS', 'UNKNOWN'), nullable=False) # 종류 : 수신, 발신, 부재중, 알수없음 phone = db.Column(db.String(40), nullable=False) # 전번 time = db.Column(db.String(40), nullable=False) # 통화시간 얼마나 했는지 created_at = db.Column(db.String(40), nullable=False) # 전화를 한 시간 user = db.relationship('Users') def get_call_log_object(self): call_log = { 'id': self.id, 'uid': self.uid, 'name': self.name, 'log_type': self.log_type, 'phone': self.phone, 'time': self.time, 'created_at': self.created_at } call_log['shop_name'] = self.user.name return call_log
class Users(db.Model): """ 사용자 테이블 """ __tablename__ = 'users' id = db.Column(db.Integer, primary_key=True) user_id = db.Column(db.String(32), nullable=False, unique=True) #아이디는 폰번호로 auth = db.Column(db.String(32), nullable=False) name = db.Column(db.String(11)) # 이름 created_at = db.Column(db.DateTime, nullable=False, default=datetime.datetime.now) # 가입일 contact = db.relationship('Contacts') call_log = db.relationship('CallLogs') message = db.relationship('Messages') period = db.relationship('Periods', uselist=False) admin = db.relationship('Admins') def get_user_object(self, period_object=False, days_object=False): user = { 'id': self.id, 'user_id': self.user_id, 'auth': self.auth, 'name': self.name, 'created_at': str(self.created_at) } if period_object: user['period'] = self.period.get_period_object( ) if self.period else None if days_object: end = datetime.datetime.strptime(self.period.end, "%Y-%m-%d") start = datetime.datetime.strptime(self.period.start, "%Y-%m-%d") value = (end - start) day = re.findall("\d+", str(value)) user['days'] = day[0] return user
class Contacts(db.Model): """ 연락처 테이블 """ __tablename__ = 'contacts' id = db.Column(db.Integer, primary_key=True) uid = db.Column(db.Integer, db.ForeignKey('users.id'), nullable=False) phone = db.Column(db.String(40), nullable=False) # 전번 name = db.Column(db.String(40), nullable=False) # 저장된 이름 created_at = db.Column(db.String(40), nullable=False) #저장된 날짜 user = db.relationship('Users') def get_contact_object(self): contact = { 'id': self.id, 'uid': self.uid, 'phone': self.phone, 'name': self.name, 'created_at': self.created_at } contact['shop_name'] = self.user.name return contact
class Notices(db.Model): """ 공지사항 테이블 """ __tablename__ = 'notices' id = db.Column(db.Integer, primary_key=True) uid = db.Column(db.Integer, db.ForeignKey('users.id'), nullable=False) #작성자 title = db.Column(db.String(40), nullable=False) # 제목 content = db.Column(db.Text, nullable=False) # 내용 created_at = db.Column(db.DateTime, nullable=False, default=datetime.datetime.now) # 생성날짜 def get_notice_object(self): notice = { 'id': self.id, 'uid': self.uid, 'title': self.title, 'content': self.content, 'created_at': str(self.created_at) } return notice
class Periods(db.Model): """ 결제관련 테이블 """ __tablename__ = 'periods' id = db.Column(db.Integer, primary_key=True) uid = db.Column(db.Integer, db.ForeignKey('users.id'), nullable=False) start = db.Column(db.String(40), nullable=False) # 시작일 end = db.Column(db.String(40), nullable=False) # 종료일 created_at = db.Column(db.DateTime, nullable=False, default=datetime.datetime.now) # 생성날짜 updated_at = db.Column(db.DateTime, nullable=False, default=datetime.datetime.now) # 생성날짜 def get_period_object(self): period = { 'id': self.id, 'uid': self.uid, 'start': self.start, 'end': self.end, 'created_at': str(self.created_at), 'updated_at': str(self.updated_at) } return period
class Messages(db.Model): """ 메시지 테이블 """ __tablename__ = 'messages' id = db.Column(db.Integer, primary_key=True) uid = db.Column(db.Integer, db.ForeignKey('users.id'), nullable=False) phone = db.Column(db.String(40), nullable=False) # 전화번호 or 이름 content = db.Column(db.Text, nullable=False) # 메시지 내용 type = db.Column(db.Enum('IN', 'OUT'), nullable=False) # 종류 : 수신, 발신, 부재중 created_at = db.Column(db.String(40), nullable=False) # 날짜 user = db.relationship('Users') def get_message_object(self): message = { 'id': self.id, 'uid': self.uid, 'phone': self.phone, 'content': self.content, 'type': self.type, 'created_at': self.created_at } message['shop_name'] = self.user.name return message
class Users(db.Model): id = db.Column(db.Integer, primary_key=True) username = db.Column(db.String(20), unique=True, nullable=False) firstname = db.Column(db.String(120), nullable=False) lastname = db.Column(db.String(120), nullable=False) email = db.Column(db.String(120), unique=True, nullable=False)