class UserSchema(ma.SQLAlchemySchema): class Meta: model = UserModel() username = ma.auto_field() explain = ma.auto_field() profile_image = ma.Nested('ImageSchema', only=["url"])
class KeywordSchema(ma.SQLAlchemySchema): class Meta: model = Keyword id = ma.auto_field() stocks = ma.auto_field() keyword = ma.auto_field()
class Meta: model = SavedPost id = ma.auto_field() user_id = ma.auto_field() created = ma.auto_field() post_id = ma.auto_field()
class DelPetRecordSchema(ma.SQLAlchemySchema): class Meta: model = PetRecord timestamp = ma.auto_field() pet_id = ma.auto_field() user_id = ma.auto_field()
class SubcategorySchema(ma.SQLAlchemySchema): class Meta: model = Subcategory name = ma.auto_field() category_id = ma.auto_field() category = Nested(CategorySchema)
class Bankchema(ma.SQLAlchemySchema): class Meta: model = Bank id = ma.auto_field() name = ma.auto_field() description = ma.auto_field()
class GallerySchema(ma.SQLAlchemySchema): class Meta: model = GalleryModel name = ma.auto_field() explain = ma.auto_field() gallery_id = ma.auto_field() gallery_type = ma.auto_field()
class UserSchema(ma.SQLAlchemySchema): class Meta: model = User include_fk = True id = ma.auto_field() username = ma.auto_field() email = ma.auto_field()
class CategorySchema(ma.SQLAlchemySchema): """Схема данных категорий товара.""" class Meta: model = Category id = ma.auto_field() name = ma.auto_field() products = ma.auto_field()
class User_schema(ma.SQLAlchemySchema): class Meta: model = User id = ma.auto_field(dump_only=True) name = ma.auto_field() password = ma.auto_field(allow_none=True, load_only=True) email = ma.auto_field()
class CartSchema(ma.SQLAlchemyAutoSchema): class Meta: model = Cart load_instance = True id = ma.auto_field(dump_only=True) idUser = ma.auto_field(required=True) products = ma.auto_field(required=True)
class CustomerSchema(ma.SQLAlchemySchema): class Meta: model = Customer id = ma.auto_field() name = ma.auto_field() email = fields.Email() budgetItems = ma.auto_field()
class CartSchema(ma.SQLAlchemySchema): class Meta: model = Cart ordered = True id = ma.auto_field() store_id = ma.auto_field() products = ma.List(ma.Nested(CartProductSchema))
class ImageSchema(ma.SQLAlchemySchema): class Meta: model = Image id = ma.auto_field() name = ma.auto_field() categories = ma.auto_field() timestamp = ma.auto_field()
class CategorySchema(ma.SQLAlchemyAutoSchema): class Meta: model = Category name = ma.auto_field() description = ma.auto_field() date_posted = ma.auto_field() products = fields.List(fields.Nested(ProductSchema))
class StoreProductsSchema(ma.SQLAlchemySchema): class Meta: model = Store ordered = True id = ma.auto_field() name = ma.auto_field() products = ma.List(ma.Nested(ProductStockSchema))
class UserSchema(ma.SQLAlchemySchema): class Meta: model = User id = ma.auto_field() email = ma.auto_field() first_name = ma.auto_field() last_name = ma.auto_field()
class ChildParentSchema(ma.SQLAlchemySchema): id = ma.auto_field() name = ma.auto_field() createdAt = fields.DateTime(format='%Y-%m-%d %H:%M:%S%z') updatedAt = fields.DateTime(format='%Y-%m-%d %H:%M:%S%z') class Meta: model = Parent ordered = True
class ProductsSchema(ma.SQLAlchemySchema): class Meta: model = Products name = ma.auto_field() price = ma.auto_field() stock = ma.auto_field() width = ma.auto_field() height = ma.auto_field()
class BudgetItemSchema(ma.SQLAlchemySchema): class Meta: model = BudgetItem include_fk = True id = ma.auto_field() name = ma.auto_field() customer_id = ma.auto_field() amount = fields.Float()
class StoreDetailSchema(ma.SQLAlchemySchema): class Meta: model = Store ordered = True id = ma.auto_field() name = ma.auto_field() address = ma.auto_field() logo_url = ma.auto_field()
class RuntimeSchema(ma.SQLAlchemyAutoSchema): def __init__(self, **kwargs): super().__init__(**kwargs) class Meta: model = Runtime include_relationships = True include_fk = True sqla_session = db.session id = ma.auto_field(dump_only=True) runtime_type = EnumField(RuntimeTypeEnum, by_value=True) available_opts = fields.Nested( 'AvailableOptionSchema', default=[], many=True, # exclude=('available_option_idddd',) ) created_at = ma.auto_field(dump_only=True) updated_at = ma.auto_field(dump_only=True) @post_dump() def __post_dump(self, data, **kwargs): if 'webapps' in data: data['webapps'] = list(map(str, data['webapps'])) if 'addons' in data: data['addons'] = list(map(str, data['addons'])) if (data['uri_template'] is not None) \ and (isinstance(data['uri_template'], str)) \ and (len(data['uri_template']) > 0): # string =====================> json / object data['uri_template'] = json.loads(data['uri_template']) return data @pre_load() def __pre_load(self, data, **kwargs): if 'uri_template' in data and data['uri_template'] is not None: # ensure uri_template is correct variables = data['uri_template']['variables'] for variable in variables: length = variable['length'] unique = variable['unique'] src = variable['src'] if unique and src == 'random': msg = "Uniqueness is not taken into account "\ "for a random variable." raise BadRequest(description=msg) if unique and length < 16 and src == 'capsule': msg = "Uniqueness of a variable required "\ "a length greater or equal to 16." raise BadRequest(description=msg) # json / object =====================> string data['uri_template'] = json.dumps(data['uri_template']) return data
class UserSchema(ma.SQLAlchemyAutoSchema): class Meta: model = UserModel load_instance = True username = ma.auto_field(required=True) password = ma.auto_field(required=True) email = ma.auto_field(required=True) isAdmin = ma.auto_field(required=True) address = ma.auto_field(required=True)
class TileStylesSchema(ma.SQLAlchemySchema): class Meta: model = TileStyles id = ma.auto_field() tile = ma.auto_field() background = ma.auto_field() border = ma.auto_field()
class VoucherSchema(ma.SQLAlchemySchema): class Meta: model = Voucher ordered = True id = ma.auto_field() code = ma.auto_field() store_id = ma.auto_field() start_date = ma.auto_field() end_date = ma.auto_field()
class CommentSchema(ma.SQLAlchemySchema): class Meta: model = CommentModel id = ma.auto_field() content = ma.auto_field() wrote_datetime = ma.auto_field() upper_comment_id = ma.auto_field() writer = ma.Nested('UserSchema', only=['username']) wrote_post = ma.Nested('PostSchema', only=['id'])
class SectorSchema(ma.SQLAlchemySchema): class Meta: model = Sector #fields = ("id", "name") id = ma.auto_field() name = ma.auto_field() #industries = ma.auto_field() #industries = ma.List(ma.HyperlinkRelated("industryresource", "industry_id")) industries = ma.Nested(industries_schema)
class ParentSchema(ma.SQLAlchemyAutoSchema): id = ma.auto_field() name = ma.auto_field() createdAt = fields.DateTime(format='%Y-%m-%d %H:%M:%S%z') updatedAt = fields.DateTime(format='%Y-%m-%d %H:%M:%S%z') child = ma.Nested(ParentChildSchema, many=True) class Meta: model = Parent ordered = True
class EmployerSchema(ma.SQLAlchemySchema): class Meta: model = Employer id = ma.auto_field() name = ma.auto_field() @post_load def make_employer(self, data, **kwargs): return Employer(**data)
class ImageSchema(ma.SQLAlchemySchema): class Meta: model = ImageModel() url = ma.Method(serialize='get_uri', deserialize='get_uri') filename = ma.auto_field() id = ma.auto_field() def get_uri(self, obj): return current_app.config["IMAGES_URL"] + obj.filename