def update_company(self, user=None): company = Company(name=self.name.data, address=self.address.data, website=self.website.data, url=self.logo.data, description=self.description.data) if user: company.user = user db.session.add(company) db.session.commit() return company
def create_user(self): user = User() #这里是添加企业用户的普通信息 user.name = self.name.data user.email = self.email.data user.password = self.password.data user.logo_img = self.image.data user.role = 20 #企业用户的权限是20 db.session.add(user) new_user = User.query.filter_by(name=user.name).first() company = Company() #下面是添加企业用户的详细信息 company.user = new_user company.website = self.web.data company.oneword = self.oneword.data company.description = self.description.data db.session.commit() return user
def iter_companies(): with open(os.path.join(os.path.dirname(__file__), '..', 'datas', 'companies.json')) as f: companies = json.load(f) for i, company in enumerate(companies): user = User.query.get(i+1) #一个企业用户对应一个企业信息 company = Company( name = company['name'], logo = company['logo'], site = fake_cn.url(), addr = company['addr'], email = fake_cn.email(), description = company['description'], about = company['about'], tags = company['tags'], welfares = company['welfares'], ) company.user_id = user.id company.user = user db.session.add(company) db.session.commit()
def update_company(self, user=None, company=None): if not company: company = Company(name=self.name.data, address=self.address.data, website=self.website.data, url=self.logo.data, phone=self.phone_number.data, profile=self.info.data, description=self.description.data) else: self.populate_obj(company) # 补录数据 company.profile = self.info.data company.phone = self.phone_number.data if user: company.user = user db.session.add(company) db.session.commit() return company