How do I retreive / insert data using sqlobject? I have read the docs
front to back, upside down, then back again...and I am still stuck as
to how to actually use this thing beyond a super trivial example...
Here's my problem (this is an extension to the 20minuteWiki tutorial):
0.) The model:
class Page(SQLObject):
pagename = StringCol(alternateID=True, length=30)
attached_files = RelatedJoin('UploadedFile')
wikidata = MultipleJoin('WikiData')
class UploadedFile(SQLObject):
filename = StringCol(alternateID=True)
abspath = StringCol()
size = IntCol()
referenced_in_pages = RelatedJoin('Page')
class WikiData(SQLObject):
data = StringCol()
mod_date_time = DateTimeCol()
revision = IntCol()
author = StringCol(length=30)
referenced_in_pages = ForeignKey('Page')
Ob) tg-admin sql drop && tg-admin sql create
1.) How do I insert data into the 'Page', now that it is joined to 1toM
to WikiData?
- I have tried:
- p = Page(pagename='FrontPage')
- dir (p)... there is no addWikiData here...
'addColumn',
'addIndex',
'addJoin',
'addUploadedFile',
2.) How do I retrieve abitrary field data from the 'Page' table?
- assuming I can get data in, how do I get data from specific fields?
in this case, i only need to grab the last wiki entry, and get the
revision value from it...pseudocode:
p = Page.select(Page.q.pagename=='FrontPage'
orderBy(wikidata.revision)).reversed()[0:1]
rev = p.wikidata.revision
This last is making my hair turn grey. I have been able to get info by
doing the following (For this example there is no wikidata table, all
the fields belong to the Page table):
last_page_added = Page.select(Page.q.pagename==pagename,
orderBy=('revision')).reversed()[0:1]
for _page in last_page_added:
new_page = Page(pagename = pagename,
data = data,
last_mod_date_time = datetime.datetime.now(),
revision = _page.revision + 1
)
Isn't this a hack? Do I really have to iterate through a one item slice
in order to get the row values? Is there a way to more elegantly access
the data?
I would expect something like:
p = Page.select(Page.q.pagename==pagename,
orderBy=('revision')).reversed()[0:1]
print p.revision
print p.data
etc.
-Todd