Skip to content

Instantly share code, notes, and snippets.

@pandada8
Last active August 29, 2015 14:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pandada8/9963ea29c79cf2b42e62 to your computer and use it in GitHub Desktop.
Save pandada8/9963ea29c79cf2b42e62 to your computer and use it in GitHub Desktop.
Peewee snippet
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