fix definition of model SanitizationEntity

This commit is contained in:
Cayo Puigdefabregas 2023-03-07 16:40:45 +01:00
parent 0ff2bcae92
commit 7534df083c
1 changed files with 18 additions and 11 deletions

View File

@ -1,11 +1,12 @@
from uuid import uuid4 from uuid import uuid4
from flask import current_app as app from flask import current_app as app
from flask import g
from flask_login import UserMixin from flask_login import UserMixin
from sqlalchemy import BigInteger, Boolean, Column, Sequence from sqlalchemy import BigInteger, Boolean, Column, Sequence
from sqlalchemy.dialects.postgresql import UUID from sqlalchemy.dialects.postgresql import UUID
from sqlalchemy_utils import EmailType, PasswordType from sqlalchemy_utils import EmailType, PasswordType
from teal.db import URL, IntEnum from teal.db import CASCADE_OWN, URL, IntEnum
from ereuse_devicehub.db import db from ereuse_devicehub.db import db
from ereuse_devicehub.resources.enums import SessionType from ereuse_devicehub.resources.enums import SessionType
@ -122,18 +123,24 @@ class Session(Thing):
class SanitizationEntity(Thing): class SanitizationEntity(Thing):
id = Column(BigInteger, primary_key=True) id = db.Column(BigInteger, primary_key=True)
company_name = Column(db.String, nullable=True) company_name = db.Column(db.String, nullable=True)
location = Column(db.String, nullable=True) location = db.Column(db.String, nullable=True)
logo = Column(db.String, nullable=True) # logo = db.Column(db.String, nullable=True)
logo = Column(URL(), nullable=True) logo = db.Column(URL(), nullable=True)
responsable_person = Column(db.String, nullable=True) responsable_person = db.Column(db.String, nullable=True)
supervisor_person = Column(db.String, nullable=True) supervisor_person = db.Column(db.String, nullable=True)
user_id = db.Column(db.UUID(as_uuid=True), db.ForeignKey(User.id)) user_id = db.Column(
db.UUID(as_uuid=True),
db.ForeignKey(User.id),
default=lambda: g.user.id,
)
user = db.relationship( user = db.relationship(
User, User,
backref=db.backref('sanitization_entity', lazy=True, collection_class=set), backref=db.backref(
collection_class=set, 'sanitization_entity', lazy=True, uselist=False, cascade=CASCADE_OWN
),
primaryjoin=user_id == User.id,
) )
def __str__(self) -> str: def __str__(self) -> str: