APIFairy icon indicating copy to clipboard operation
APIFairy copied to clipboard

Schema in separate file

Open JarriqTheTechie opened this issue 3 years ago • 3 comments

How to declare Schema in separate file? As well as using blueprints?

JarriqTheTechie avatar Feb 09 '22 16:02 JarriqTheTechie

I don't understand. There is absolutely no required structure. You can put your schemas anywhere you like.

miguelgrinberg avatar Feb 09 '22 18:02 miguelgrinberg

When defining schema in separate file how do we go about setting it up.

I'm doing this

#UserSchema.py from app import ma

class UserSchema(ma.Schema): email = Str()

I get a ton of import errors doing that.

JarriqTheTechie avatar Feb 10 '22 00:02 JarriqTheTechie

I can't really tell you how to fix this, but it is a structural problem in your app. See https://github.com/miguelgrinberg/microblog-api for an example application with schemas on a schemas.py file.

miguelgrinberg avatar Feb 10 '22 09:02 miguelgrinberg

Reference in new iss

If that is circular imports then change to import ma from another file, for example utils.

jorgelaranjo avatar Dec 08 '23 14:12 jorgelaranjo