[Models] Fixed optional detection
This commit is contained in:
parent
d6475604e9
commit
cb342c07e8
|
@ -14,10 +14,8 @@ class ModelSerializeMixin:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
import typing
|
import typing
|
||||||
|
hint = typing.get_type_hints(self.__class__)[param]
|
||||||
if typing.get_origin(self.__class__.__annotations__[param]) is typing.Union and typing.get_args(
|
if typing.get_origin(hint) is typing.Union and len(typing.get_args(hint)) == 2 and typing.get_args(hint)[1] is type(None):
|
||||||
self.__class__.__annotations__[param]
|
|
||||||
)[1] is type(None):
|
|
||||||
return getattr(self, param) is None
|
return getattr(self, param) is None
|
||||||
|
|
||||||
def serialize(self):
|
def serialize(self):
|
||||||
|
|
|
@ -80,7 +80,7 @@ class Event(db.Model, ModelSerializeMixin):
|
||||||
|
|
||||||
id: int = db.Column(db.Integer, primary_key=True)
|
id: int = db.Column(db.Integer, primary_key=True)
|
||||||
start: datetime = db.Column(UtcDateTime, nullable=False)
|
start: datetime = db.Column(UtcDateTime, nullable=False)
|
||||||
end: datetime = db.Column(UtcDateTime)
|
end: Optional[datetime] = db.Column(UtcDateTime)
|
||||||
description: Optional[str] = db.Column(db.String(255))
|
description: Optional[str] = db.Column(db.String(255))
|
||||||
type: EventType = db.relationship("EventType")
|
type: EventType = db.relationship("EventType")
|
||||||
jobs: list[Job] = db.relationship(
|
jobs: list[Job] = db.relationship(
|
||||||
|
|
Loading…
Reference in New Issue