Last active
August 29, 2015 14:15
-
-
Save pandada8/9963ea29c79cf2b42e62 to your computer and use it in GitHub Desktop.
Peewee snippet
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from peewee import Model | |
from playhouse.db_url import connect | |
db = connect(os.env.get('DATABASE') or options.database) | |
class BaseModel(Model): | |
@classmethod | |
def try_get(cls, **kwargs): | |
try: | |
return cls.get(**kwargs) | |
except cls.DoesNotExist: | |
return kwargs.get('default') | |
class Meta: | |
database = db |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment