Disclaimer: I know this question has been asked a lot, and I am fairly new
to programming. I have searched for some time in this forum and in the web
on how to create a search option in the index page where people can search
for a keyword appearing in the title or the body of a blog post that I
created by following Massimo's video tutorial.
I need some help here... I'll try to post my models, views and controllers
code here.
*Models:*
db.define_table('blog_post',
Field('title',requires=IS_NOT_EMPTY()),
Field('body','text',requires=IS_NOT_EMPTY()),
auth.signature)
# auth.signature does all of the stuff below
#Field('created_on','datetime'),
#Field('created_by','reference auth_user'),
#Field('modified_by','reference auth_user'),
#Field('modified_on','datetime'))
db.define_table('blog_comment',
Field('blog_post','reference blog_post'),
Field('body','text',requires=IS_NOT_EMPTY()),
auth.signature)
*Controller:*
import web2py_utils
def index():
if len(request.args): page=int(request.args[0])
else: page=0
items_per_page=6
limitby=(page*items_per_page,(page+1)*items_per_page+1)
rows = db(db.blog_post).select(db.blog_post.ALL,
orderby=~db.blog_post.created_on, limitby=limitby)
return dict(rows=rows, page=page,items_per_page=items_per_page)
#rows = db(db.blog_post).select(orderby=db.blog_post.title.upper())
#return locals()
#########################################################################
# a controller for searching the post body
#########################################################################
*View:*
{{extend 'layout.html'}}
<!-- Code below has been commented out-->
<i>Search Posts</i>
<!--<form action="" method="get"><input name="keywords"></input></form>-->
<h2>All Posts</h2>
<table Class="table">
{{for row in rows:}}
<table style="width:100%">
<col width="100">
<col width="250">
<col width="25">
<col width="25">
<tr>
<td><a href="{{=URL('show', args=row.id)}}">{{=row.title}}</a></td>
<td>{{=row.body}}</td>
<td>{{=row.created_on}}</td>
<td>{{=row.created_by.first_name}}
{{=row.created_by.last_name}}</td>
</tr>
{{pass}}
</table>
Thanks in advance for your help.
--
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
---
You received this message because you are subscribed to the Google Groups
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.