peewee

A little ORM
Download

peewee Ranking & Summary

Advertisement

  • Rating:
  • License:
  • MIT/X Consortium Lic...
  • Publisher Name:
  • Charles Leifer
  • Publisher web site:
  • http://www.charlesleifer.com/blog/

peewee Tags


peewee Description

A little ORM peewee - fiddling around with an ORM.model definitions and schema creationsmells like django:import peeweeclass Blog(peewee.Model): title = peewee.CharField() def __unicode__(self): return self.titleclass Entry(peewee.Model): title = peewee.CharField(max_length=50) content = peewee.TextField() pub_date = peewee.DateTimeField() blog = peewee.ForeignKeyField(Blog) def __unicode__(self): return '%s: %s' % (self.blog.title, self.title)create some tables:>>> Blog.create_table()>>> Entry.create_table()foreign keys work like django's >>> b = Blog(title="Peewee's Big Adventure") >>> b.save() >>> e = Entry(title="Greatest movie ever?", content="YES!", blog=b) >>> e.save() >>> e.blog >>> for e in b.entry_set: ... print e.title ... Greatest movie ever?bizarre queryingqueries come in 4 flavors (select/update/insert/delete):>>> for i in xrange(50):... b = Blog(title='blog-%d' % i)... b.save()... for j in xrange(i):... e = Entry(title='entry-%d' % j, blog=b)... e.save()...>>> >>> >>> >>> Blog.select().join(Entry).where(title__contains='entry-29').count()20 Requirements: · Python


peewee Related Software