Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import peewee
- db = peewee.SqliteDatabase('/somepath')
- class BaseModel(peewee.Model):
- class Meta:
- database = db
- class Page(BaseModel):
- url = peewee.CharField(unique=True)
- class Tag(BaseModel):
- name = peewee.CharField(index=True)
- class PageTag(BaseModel):
- page = peewee.ForeignKeyField(Page, related_name='_pagetags', index=True)
- tag = peewee.ForeignKeyField(Tag, index=True)
- query = Page.select(Page.url)
- tag = 'some_tag'
- # this works:
- query = query.where(
- orm.Page.id << [
- i.page.id for i in
- orm.PageTag.select(orm.PageTag.page)
- .where(
- orm.PageTag.tag ==
- orm.Tag.get(orm.Tag.name == tag))])
- # this doesn't:
- query = query.where(tag << orm.Page._pagetags)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement