A "ModelPlus" subclass i'm working on to simplify how i work with my models #153
chrisdewa
started this conversation in
Show and tell
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
So I've been using ODMantic for a while now and I'm experimenting with subclassing the default Model.
After I've defined my engine elsewhere and made it accessible to the class...
And I use this new Model class to interact with the database.
Each instance now gets a save method and the class itself gets some cool classmethods as well.
I don't very much fancy making my own query expressions so I made a method that does them for me.
And I often search for a document and create an instance if it doesn't exist so I simplified it like this:
If an item doesn't exist with
a == 123
andb == 'foo'
then I get a new instance from it.I'm still working on this, any ideas or suggestions?
Beta Was this translation helpful? Give feedback.
All reactions