class StoreSchema(ma.SQLAlchemyAutoSchema): items = ma.Nested(ItemSchema, many=True) class Meta: model = StoreModel include_relationships = True include_fk = True load_instance = True id = ma.auto_field(dump_only=True)
class OrganizationSchema(ma.ModelSchema): users = ma.Nested("UserSchema", exclude=("organizations", ), many=True) class Meta: model = OrganizationModel dump_only = ( "id", "uuid", )
class StoreSchema(ma.ModelSchema): items = ma.Nested( ItemSchema, many=True ) # the store contains many item schema, so the items property is not something we are going to be loading, # but smth we gonna be dumping class Meta: model = StoreModel dump_only = ("id",) include_fk = True
class StoreSchema(ma.SQLAlchemyAutoSchema): items = ma.Nested(ItemSchema, many=True) class Meta: model = StoreModel dump_only = ("id", ) include_fk = True @post_load def make_store(self, data, **kwargs): return StoreModel(**data)
class UserSchema(ma.SQLAlchemySchema): class Meta: model = User id = ma.auto_field() username = ma.auto_field() firstname = ma.auto_field() lastname = ma.auto_field() isAdmin = ma.auto_field() user_profile = ma.Nested("UserProfileSchema")
class StateSchema(ma.ModelSchema): municipalities = ma.Nested(MunicipalitySchema, many=True) class Meta: model = StateModel dump_only = ( "id", "uuid", )
class UserSchema(ma.SQLAlchemyAutoSchema): orders = ma.Nested(OrderSchema, many=True) class Meta: model = UserModel load_only = ( "password", "orders.user_id", ) dump_only = ("id", ) load_instance = True
class UserSchema(ma.ModelSchema): items = ma.Nested(ItemSchema, many=True) class Meta: model = UserModel load_only = ("password", ) dump_only = ("id", "confirmation") @pre_dump def _pre_dump(self, user: UserModel): user.confirmation = [user.most_recent_confirmation] return user
class StoreSchema(ma.SQLAlchemyAutoSchema): items = ma.Nested(ItemSchema, many=True) class Meta: #here' we are giving marshmellow thoe model it needs to create #only by explaining that we can delete the usermodel init method # A Building block of sorts model = StoreModel dump_only = ("id", ) include_fk = True load_instance = True
class PostsSchema(ma.ModelSchema): comments = ma.Nested(CommentSchema, many=True) class Meta: model = PostsModel dump_only = ( "id", "created_at", ) load_only = ("user", ) include_fk = True
class StoreSchema(ma.ModelSchema): # from store model, store contains many items items = ma.Nested( ItemSchema, many=True ) # means items property in the store is something that is nested inside the # store and it contains many item schema, we are only dumping but not loading class Meta: model = StoreModel # this is extending the functionality of marshmallow schema and link up the user model dump_only = ("id", ) include_fk = True
class DishSchema(ma.SQLAlchemySchema): class Meta: model = Dish id = ma.auto_field() dish_name = ma.auto_field() main_dish = ma.auto_field() description = ma.auto_field() course = ma.auto_field() cuisine = ma.auto_field() prep_hour = ma.auto_field() prep_minute = ma.auto_field() cook_hour = ma.auto_field() cook_minute = ma.auto_field() serving_count = ma.auto_field() es_keywords = ma.auto_field() status = ma.auto_field() created_at = ma.auto_field() updated_at = ma.auto_field() user = ma.Nested("UserSchema", many=False) ingredients = ma.Nested("IngredientSchema", many=True) instruction = ma.Nested("PrepInstructionSchema", many=True)
class UserSchema(ma.SQLAlchemyAutoSchema): confirmation = ma.Nested(ConfirmationSchema, many=True) class Meta: model = UserModel load_only = ("password", ) dump_only = ("id", "confirmation") load_instance = True @pre_dump def dump_it(self, user: UserModel, **kwargs): user.confirmation = [user.most_recent_confirmation] # print(user.confirmation[0].id) return user
class OrderSchema(ma.SQLAlchemyAutoSchema): items_list = ma.Nested(ItemsToOrderSchema, many=True) class Meta: model = OrderModel load_only = ("token", ) dump_only = ( "id", "status", ) include_fk = True include_relationships = True load_instance = True
class MemberSchema(ma.SQLAlchemyAutoSchema): tokens = ma.Nested(TokenSchema, many=True) @pre_load def set_password_hash(self, member_data: Dict, **kwargs) -> Dict: if "password" in member_data: member_data["password_hash"] = generate_password_hash( member_data.pop("password") ) return member_data class Meta: model = MemberModel load_only = ("password_hash", "role") dump_only = ("id",) include_fk = True load_instance = True
class RecipeSchema(ma.SQLAlchemyAutoSchema): class Meta: model = Recipe measures = ma.Nested(MeasureSchema, many=True)
class MeasureSchema(ma.SQLAlchemyAutoSchema): class Meta: model = Measure unit = ma.Pluck(UnitSchema, "name") ingredient = ma.Nested(IngredientSchema)
class StoreSchema(ma.ModelSchema): items = ma.Nested(ItemSchema, many = True)# to define FK relationship class Meta: meta = StoreModel dump_only = ('id',) include_fk = True
class ServiceSchema(ma.SQLAlchemyAutoSchema): sources = ma.Nested(SourceServicSchema, many=True) class Meta: model = ServiceModel dump_only = ("id",)
class Meta: model = StockModel ordered = True positions = ma.Nested(PositionSchema, many=True)
class CompanySchema(ma.SQLAlchemyAutoSchema): class Meta: model = CompanyModel load_instance = True users = ma.Nested(UserSchema, many=True)
class MovieSchema(ma.ModelSchema): class Meta: model = MovieModel strict = True titles = ma.List(ma.Nested('TitleSchema'))