class Product(db.Model): '''存放产品相关信息 ''' __tablename__ = 'product' id = db.Column(db.Integer, primary_key=True) name = db.Column(db.String(100)) description = db.Column(db.String(200), default="") owner = db.Column(db.String(100)) modified_by = db.Column(db.String(100)) created = db.Column(db.DateTime, default=datetime.now()) updated = db.Column(db.DateTime, default=datetime.now()) def __init__(self, name, description, owner, modified_by): self.name = name self.description = description self.owner = owner self.modified_by = modified_by self.created = datetime.now() self.updated = datetime.now() def update(self): self.updated = datetime.now() db.session.commit() def save(self): db.session.add(self) db.session.commit() def delete(self): db.session.delete(self) db.session.commit()
class Opportunity(db.Model): '''存放销售机会相关信息 ''' __tablename__ = 'opportunity' id = db.Column(db.Integer, primary_key=True) name = db.Column(db.String(100)) source = db.Column(db.String(200), default="") next_contacts = db.Column(db.String(100)) next_date = db.Column(db.DateTime, default=datetime.now()) created = db.Column(db.DateTime, default=datetime.now()) updated = db.Column(db.DateTime, default=datetime.now()) def __init__(self, name, source, next_contacts): self.name = name self.source = source self.next_contacts = next_contacts self.next_date = datetime.now() + timedelta(days=3) self.created = datetime.now() self.updated = datetime.now() def update(self): self.updated = datetime.now() db.session.commit() def save(self): db.session.add(self) db.session.commit() def delete(self): db.session.delete(self) db.session.commit()
class User(db.Model, UserMixin): id = db.Column(db.Integer, primary_key=True) username = db.Column(db.String(20), unique=True, nullable=False) email = db.Column(db.String(120), unique=True, nullable=False) image_file = db.Column(db.String(20), nullable=False, default="default.jpeg") password = db.Column(db.String(20), nullable=False) pos_id = db.Column(db.Integer, unique=True, nullable=False) hisaab = db.relationship("Hisaab", backref="fos", lazy="dynamic") def get_reset_token(self, expires_sec=1800): s = Serializer(app.config["SECRET_KEY"], expires_sec) return s.dumps({"user_id": self.id}).decode("utf-8") @staticmethod def verify_reset_token(token): s = Serializer(app.config["SECRET_KEY"]) try: user_id = s.loads(token)["user_id"] except: return None return User.query.get(user_id) def __repr__(self): return f"User('{self.username}', '{self.email}', '{self.pos_id}')"
class Cliente(db.Model): __tablename__ = "cliente" id = db.Column(db.Integer, primary_key=True) nome = db.Column(db.String(30)) historico_status = db.Column(db.String(100)) observacoes = db.Column(db.String) email = db.Column(db.String) telefone = db.Column(db.Integer) endereco = db.Column(db.String) status = db.Column(db.String) datainsercao = db.Column(db.String) prospeccao = db.Column(db.String) def __init__(self, nome, email, telefone, endereco, status, datainsercao, prospeccao): self.nome = nome self.email = email self.telefone = telefone self.endereco = endereco self.status = status self.datainsercao = datainsercao self.prospeccao = prospeccao self.historico_status = "--------,--------,--------,--------,--------,--------" self.observacoes = "Sem comentarios Ainda!"
class User(db.Model, UserMixin): """User/Admin model""" id = db.Column(db.INTEGER, primary_key=True) username = db.Column(db.String(20), unique=True, nullable=False) email = db.Column(db.String(120), unique=True, nullable=False) password = db.Column(db.String(60), unique=True, nullable=False) def __repr__(self): return "User({}, {})".format(self.username, self.email)
class Lead(db.Model): """Lead model""" id = db.Column(db.INTEGER, primary_key=True) name = db.Column(db.String(50)) company = db.Column(db.String(50)) phone = db.Column(db.String(20)) email = db.Column(db.String(120), unique=True) touches = db.relationship('Touch', backref='author') def __repr__(self): return "Lead({}, {})".format(self.name, self.email)
class User(db.Model, UserMixin): """ Таблица зарегестрированных пользователей """ id = db.Column(db.Integer, primary_key=True) user = db.Column(db.String(64), index=True) email = db.Column(db.String(64), index=True, unique=True) password_hash = db.Column(db.String(128)) created_on = db.Column(db.DateTime, default=datetime.utcnow) clients = db.relationship('Client', backref='own_client', lazy='dynamic') def __repr__(self): return f"<User: {self.user}>" def set_password(self, password): self.password_hash = generate_password_hash(password) def check_password(self, password): return check_password_hash(self.password_hash, password)
class Admin(db.Model, UserMixin): '''管理员表 ''' __tablename__ = 'admin' id = db.Column(db.Integer, primary_key=True) name = db.Column(db.String(200), index=True) email = db.Column(db.String(200), index=True) phone = db.Column(db.String(200)) password = db.Column(db.String(200)) status = db.Column(db.String(10), default=1) last_login = db.Column(db.DateTime, default=datetime.now()) created = db.Column(db.DateTime, default=datetime.now()) updated = db.Column(db.DateTime, default=datetime.now()) def __init__(self, name, email, password): self.name = name self.email = email self.set_password(password) self.created = datetime.now() self.updated = datetime.now() def __repr__(self): return '<User %r>' % self.name def update(self): self.updated = datetime.now() db.session.commit() def save(self): db.session.add(self) db.session.commit() def set_password(self, password): self.password = generate_password_hash(password) def check_password(self, password): return check_password_hash(self.password, password) def delete(self): db.session.delete(self) db.session.commit()
class Currency(db.Model, BaseModel, RootModel): __tablename__ = "currencies" name = db.Column( db.String(3), index=True, unique=True, nullable=False, ) value_usd = db.Column(db.Float(), default=1.0) deals = db.relationship("Deal", backref="currency") def __str__(self): return self.name
class Phone(db.Model, BaseModel): __tablename__ = "phones" telephone = db.Column( db.String(255), index=True, nullable=False, ) user_id = db.Column(db.String, db.ForeignKey("users.id")) contact_id = db.Column(db.String, db.ForeignKey("contacts.id")) company_id = db.Column(db.String, db.ForeignKey("companies.id")) def __str__(self): return self.telephone
class Email(db.Model, BaseModel): __tablename__ = "emails" email = db.Column( db.String(255), index=True, nullable=False, ) user_id = db.Column(db.String, db.ForeignKey("users.id")) contact_id = db.Column(db.String, db.ForeignKey("contacts.id")) organization_id = db.Column(db.String, db.ForeignKey("organizations.id")) company_id = db.Column(db.String, db.ForeignKey("companies.id")) def __str__(self): return self.email
class Customer(db.Model): '''客户表 ''' __tablename__ = 'customer' id = db.Column(db.Integer, primary_key=True) name = db.Column(db.String(100), index=True) phone = db.Column(db.String(100), index=True, default='') email = db.Column(db.String(100), default='') owner = db.Column(db.String(100)) customer_details = db.Column(db.String(250), default='') status = db.Column(db.String(10), default=1) sex = db.Column(db.String(10), default=1) addr = db.Column(db.String(250)) company = db.Column(db.String(200)) note = db.Column(db.String(250)) group = db.Column(db.String(200)) tax_id = db.Column(db.String(100), default='') modified_by = db.Column(db.String(100)) created = db.Column(db.DateTime, default=datetime.now()) updated = db.Column(db.DateTime, default=datetime.now()) def __init__(self, name, sex, phone, email, company, addr, note, tax_id, owner): self.name = name self.sex = sex self.phone = phone self.email = email self.addr = addr self.note = note self.owner = owner self.modified_by = owner self.tax_id = tax_id self.company = company self.created = datetime.now() self.updated = datetime.now() def __repr__(self): return '<User %r>' % self.name def update(self): self.updated = datetime.now() db.session.commit() def save(self): db.session.add(self) db.session.commit() def delete(self): db.session.delete(self) db.session.commit()