Closed Alain1405 closed 8 years ago
You have to write your own field class if you want a ToOne that just accepts any reference. It is not difficult to do, but out of scope for the potion package.
Alternatively you can simply make a generic "taggable items" resource that covers all models that can be associated with a tag, and then have a fields.ToOne('taggable')
.
Ok, I see. When you mean a generic "taggable items" resource you mean that a Potion resource can point to multiple models? Or a SqlAlchemy Model that points to multiple tables?
A Potion resource that can point to multiple models, which is easier if you have an SQLAlchemy model that points to multiple tables.
As I need to associate some tags (rfid, nfc and so on) to multiple resources, I created a polymorphic association between TagsSet and a resource.
I use the following mixin for extending SqlAlchemy models which have tags:
Then I extend a model with the mixin:
You can see the association uses as discriminator the parent_type. Then I can do something like:
Where resource can be of any type.
Is there a way to set this up on flask_potion?