use populate_obj

This commit is contained in:
Cayo Puigdefabregas 2023-03-07 16:39:52 +01:00
parent 1e62af56a6
commit 0ff2bcae92
1 changed files with 11 additions and 9 deletions

View File

@ -141,15 +141,17 @@ class SanitizationEntityForm(FlaskForm):
return True
def save(self, commit=True):
sanitation_data = SanitizationEntity(
logo=URL(self.logo.data),
company_name=self.company_name.data,
location=self.location.data,
responsable_person=self.responsable_person.data,
supervisor_person=self.supervisor_person.data,
user=g.user,
)
db.session.add(sanitation_data)
if isinstance(self.logo.data, str):
self.logo.data = URL(self.logo.data)
sanitation_data = SanitizationEntity.query.filter_by(user_id=g.user.id).first()
if not sanitation_data:
sanitation_data = SanitizationEntity(user_id=g.user.id)
self.populate_obj(sanitation_data)
db.session.add(sanitation_data)
else:
self.populate_obj(sanitation_data)
if commit:
db.session.commit()