Hi,

I am having trouble using DAL the web2py way. I am trying to create a
personal website so I can post articles. I have all my articles for
different subjects stored in a single table with a field "main_tag",
which tells the subject of the article. I will display them on the
webpage in different pages, organized by subject.

# ==============================================#
db = DAL('sqlite://storage.sqlite')

db.define_table('articles',
   Field('title', 'string'),
   Field('body', 'text'),
   Field('main_tag', 'string'),
   Field('sec_tag', 'string'))

db.articles.title.requires = IS_NOT_IN_DB(db, db.articles.title)
db.articles.body.requires = IS_NOT_EMPTY()
db.articles.main_tag.requires = IS_NOT_EMPTY()
# ==============================================#

How do I write the command below the web2py way, instead of using
executesql()?

# Selects articles by subject ("main_tag" field)
# request.args() used in the view files
def articles():
   title = db.executesql('SELECT title FROM articles WHERE id=%s AND
main_tag=%s' % (request.args(0), request.args(1)))
    body = db.executesql('SELECT body FROM articles WHERE id=%s AND
main_tag=%s' % (request.args(0), request.args(1)))
    return dict(title=title, body=body)

Thanks,

Eduardo

Reply via email to