Questions tagged [marshmallow-sqlalchemy]
54 questions
0
votes
1 answer
How to handle one-to-many relationship during HATEOAS serialization in Marshmallow?
Trying to implement a rather simple REST API in Python (SQLAlchemy + Marshmallow) using HATEOAS resource linking, I am stuck when attempting to create "smart hyperlinks" for one-to-many relationships.
Let's consider the classic book example: One…

ahuemmer
- 1,653
- 9
- 22
- 29
0
votes
0 answers
How to make all fields "required" in SQLAlchemyAutoSchema in flask_marshmallow?
I am using SQLAlchemyAutoSchema to automatically generate fields for the model, by default, it sets all fields' required status to False. How can I make all fields required?
class ReferralOuctomeSchema(ma.SQLAlchemyAutoSchema):
class Meta:
…

Ayaz49
- 325
- 2
- 4
- 18
0
votes
1 answer
Set Required=True based on a condition in marshmallow
I was wondering whether there is a way in marshmallow to have a field to be required depending on another value.
Eg:
{ 'name':'Tom' }
{ 'name':'Arthur', 'job':'teacher' }
I'd like to know if there is a way to make the field job required if…

codeplay_
- 31
- 5
0
votes
0 answers
Unbind Marshmallow transient object from database session
I'm using marshmallow_sqlalchemy library to build object from objects from schemas and then add the database. My Marshmallow and Sqlalchemy classes are defined as follows:
from marshmallow_sqlalchemy import ModelSchema
from marshmallow import…

Mehdi Ben Hamida
- 893
- 4
- 16
- 38
0
votes
1 answer
sqlalchemy.orm.exc.UnmappedInstanceError: Class 'builtins.dict' is not mapped AND using marshmallow-sqlalchemy
I don't get it. I'm trying to start a brand new table in MS SQL Server 2012 with the following:
In SQL Server:
TABLE [dbo].[Inventory](
[Index_No] [bigint] IDENTITY(1,1) NOT NULL,
[Part_No] [varchar(150)] NOT NULL,
[Shelf] [int] NOT NULL,
[Bin]…

Steve Brother
- 838
- 2
- 11
- 21
0
votes
1 answer
How to define a marshamllow List field using marshmallow_sqlalchemy
I'm trying to create a Schema using marshmallow_sqlalchemy. I want to create a list out of two entries of the Database, x_coordinate and y_coordinate, however, I'm not sure how to do that.
Here's the Schema
from marshmallow_sqlalchemy import…

damart
- 1
0
votes
1 answer
sqlalchemy relationship select from other table instead of insert
I'm having difficulties in relationships. I have users and roles and defined model and schema for them.
the problem is when I try to add a new user with a previously defined role (I have its ID and name)it will try to update/insert the role table by…

imax
- 1
0
votes
1 answer
Marshmallow deserialization [(obj, "str"), (obj, "str"), (obj, "str"), ...]
I'm working with an existing mssql database, where I'm not able to make any changes. Trying to make an API using Flask and Marshmallow. I have some issues deserializing the following query returning all people working on a project.
query = (
…

thp44
- 11
- 3
0
votes
1 answer
Python externalise database model file
I'm building a web API in Python flask.
... which needs library SQLAlchemy for db connectivity
... which needs marshmallow to render database results as JSON
Working through a number of examples I now have this code in my app.py file which returns a…

Nick.Mc
- 18,304
- 6
- 61
- 91
0
votes
1 answer
Filter rows in child table using parent table having one to many relationship sqlalchemy
I have two tables having one to many relationship.
I want to find all rows of child where type is "abc"
class Parent(base):
__tablename__ = "parent"
id = Column("id", String, primary_key=True)
parent = relationship("Child",…

Avenger
- 793
- 11
- 31
0
votes
1 answer
How to create a Marshmallow SQL schema for GeoJson
I am trying to create an API using flask, SQLAlchemy, Marshmallow, PostGIS that return GeoJson FeatureCollection. I want to be able to work with any Geo Objects (Point, Polygone,...).
I tried many things but never successfully recreated the GeoJson…

SimBa
- 1
- 1
0
votes
1 answer
Scalarize a nested field using marshmallow
I have two Database Models like this
class Setting(db.Model):
id = db.Column(db.Integer, id=True)
container_id = ST_db.Column(ST_db.Integer, db.ForeignKey('settings_container.id'))
setting_name = ST_db.Column(ST_db.String(50))
…

SAK
- 169
- 2
- 11
0
votes
1 answer
Parse Enum Output with Flask Marshmallow Schema
I have a question about flask marshmallow schema. So, I create models like an example below.
class ID(db.Model):
__abstract__ = True
id = db.Column(db.Integer, autoincrement=True, primary_key=True)
class Timestamp(db.Model):
…
0
votes
1 answer
How to add a custom field in Flask-Marshmallow which is not a part of my SQLAlchemy Model
Suppose I have my Model class as below.
class BankAccount(db.Model):
a = db.Column(db.Integer, primary_key=True)
b = db.Column(db.String(80))
And my Schema looks like the below.
class CreateAccountSchema(ma.SQLAlchemyAutoSchema):
class…

Vishal Verma
- 43
- 1
- 6
0
votes
1 answer
How to serialize a nested object with the many-to-one relationship in one side?
I face some troubles serializing an object with Marshmallow-sqlAlchemy.
I have two objects:
class Product(Model):
__tablename__: product_table_name
id = Column(Integer, primary_key=True)
name = Column(String)
class BasketItem(Model):
…

Sergio Lema
- 1,491
- 1
- 14
- 25