python - Subscription modelling in Flask SQLAlchemy -


i trying model following scenario in flask sqlalchemy:

there list of subscriptionpacks available purchase. when particular user buys subscriptionpack start instance of subscription.

the model follows:

erd

a user can have many subscriptions (only 1 of active @ time) , each subscription referencing 1 subscriptionpack.

how modelled in sqlalchemy?

currently have user.id , subscriptionpack.id referenced db.foreignkey in subscriptions model. , have subscriptions referenced db.relationship in users table. seems inconsistent , wrong , leading me have hand-code lot of sql statements return right results.

any how right?

for stumble upon this, looking bidirectional sqlalchemy association object pattern.

this allows intermediate table of many-to-many have it's own stored details. in instance above subscription table needed association object (has it's own class).


Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -