first push
This commit is contained in:
28
backend/models/TrainingProject.py
Normal file
28
backend/models/TrainingProject.py
Normal file
@@ -0,0 +1,28 @@
|
||||
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
|
||||
Reference in New Issue
Block a user