PeeWee - fikle rundt med en ORM.
modell definisjoner og skjema skapelse
lukter Django:
import peewee
klasse Blogg (peewee.Model):
& Nbsp; title = peewee.CharField ()
& Nbsp; def __unicode __ (egen-):
& Nbsp; retur self.title
klasse Entry (peewee.Model):
& Nbsp; title = peewee.CharField (MAX_LENGTH = 50)
& Nbsp; content = peewee.TextField ()
& Nbsp; pub_date = peewee.DateTimeField ()
& Nbsp; blogg = peewee.ForeignKeyField (Blogg)
& Nbsp; def __unicode __ (egen-):
& Nbsp; return '% s:% s'% (self.blog.title, self.title)
lage noen tabeller:
>>> Blog.create_table ()
>>> Entry.create_table ()
utenlandske tastene fungerer som Djangos
& Nbsp; >>> b = Log (title = "Peewee Big Adventure")
& Nbsp; >>> b.save ()
& Nbsp; >>> e = Entry (tittel = "Greatest film noensinne", content = "! JA", blogg = b)
& Nbsp; >>> e.save ()
& Nbsp; >>> e.blog
& Nbsp;
& Nbsp; >>> for e i b.entry_set:
& Nbsp; ... print e.title
& Nbsp; ...
& Nbsp; Greatest filmen noensinne?
bisarre spørring
spørringer kommer i 4 smaker (velg / oppdatering / sette inn / slette):
>>> For jeg i xrange (50):
... B = Log (title = 'Blog% d'% i)
... B.save ()
... For j i xrange (i):
... E = Entry (title = 'personaliserte% d'% j, blogg = b)
... E.save ()
...
>>> [Obj.title for obj i Blog.select (). Hvor (title__contains = '0')]
[U'blog-0 ', u'blog-10', u'blog-20 ', u'blog-30', u'blog-40 "]
>>> [Obj.title for obj i Blog.select (). Nummereres (3, 10)]
[U'blog-20 ', u'blog-21', u'blog-22 ', u'blog-23', u'blog-24 ',
& Nbsp; u'blog-25 ', u'blog-26', u'blog-27 ', u'blog-28', u'blog-29 ']
>>> [Obj.title for obj i Blog.select (). Delta (Entry) .Hvor (title__contains = 'entry-45')]
[U'blog-46 ', u'blog-47', u'blog-48 ', u'blog-49']
>>> Blog.select (). Delta (Entry) .Hvor (title__contains = 'entry-29'). Teller ()
20
Krav :
- Python
Kommentarer ikke funnet