Skip to content

Instantly share code, notes, and snippets.

@chadwhitacre chadwhitacre/
Last active Aug 29, 2015

What would you like to do?
"""Here's how you implement Foo(pkid) with postgres.orm 2.1.x.
Discovered at PyTennesse with @wlphoenix @PederSchacht et al.
class Foo(Model):
typname = 'foo'
def __new__(cls, pkid_or_record):
if type(pkid_or_record) is int:
obj = 'select foo.*::foo from foo where pkid=%s'
, (pkid_or_record,)
return obj
return super().__new__(cls) # This is the Python 3 version of super.
def __init__(self, record):
if type(record) is dict:
Model.__init__(self, record)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.