from stdnet.odm import StdModel, CharField, Router
class Bar(StdModel):
foo = CharField(primary_key=True, unique=True)
if __name__ == '__main__':
models = Router('redis://localhost:6379?db=1')
models.register(Bar)
with models.session().begin() as transaction:
transaction.add(models.bar.new(foo="Hello world"))
transaction.add(models.bar.new(foo="Goodbye world"))
with models.session().begin() as transaction:
transaction.add(models.bar.new(foo="Hello world"))
transaction.add(models.bar.new(foo="Goodbye world"))
for f in models.bar.query().all():
print '%r = %s' % (f, f.foo)
Output
Bar: Bar object = Hello world
Bar: Bar object = Goodbye world
Bar: Bar object = Hello world
Bar: Bar object = Goodbye world
FYI: I am running python-stdnet 0.8.2 on Python 2.7.5+ with Redis 2.8.2 on Ubuntu. Additionally have tried with python-stdnet 0.9a3.
Test-case
Output
FYI: I am running python-stdnet 0.8.2 on Python 2.7.5+ with Redis 2.8.2 on Ubuntu. Additionally have tried with python-stdnet 0.9a3.