29 lines
1.0 KiB
Python
29 lines
1.0 KiB
Python
from database.database import db
|
|
|
|
class TrainingProject(db.Model):
|
|
__tablename__ = 'training_project'
|
|
|
|
project_id = db.Column(db.Integer, primary_key=True, unique=True, autoincrement=True)
|
|
title = db.Column(db.String(255), nullable=False)
|
|
description = db.Column(db.String(500))
|
|
classes = db.Column(db.JSON, nullable=False)
|
|
project_image = db.Column(db.LargeBinary)
|
|
project_image_type = db.Column(db.String(100))
|
|
|
|
def to_dict(self):
|
|
result = {
|
|
'project_id': self.project_id,
|
|
'title': self.title,
|
|
'description': self.description,
|
|
'classes': self.classes,
|
|
'project_image_type': self.project_image_type
|
|
}
|
|
if self.project_image:
|
|
import base64
|
|
base64_data = base64.b64encode(self.project_image).decode('utf-8')
|
|
mime_type = self.project_image_type or 'image/png'
|
|
result['project_image'] = f'data:{mime_type};base64,{base64_data}'
|
|
else:
|
|
result['project_image'] = None
|
|
return result
|