hello ,

-am making a blog website and it has images but i get the same image
for all the posts  , please help me with the select   , here is my
code :

db.py :
db.define_table('blogpost',Field('title'),Field('post','text'),Field('author'),Field('datetime','datetime',default=request.now))
db.blogpost.title.requires = [IS_NOT_EMPTY(),
IS_NOT_IN_DB(db,db.blogpost.title)]
db.blogpost.author.requires = IS_NOT_EMPTY()
db.blogpost.post.requires = IS_NOT_EMPTY()

db.define_table('blogcomments',Field('author'),Field('email'),Field('comment','text'),Field('commenttime','datetime',default=request.now),Field('blog_id',db.blogpost))
db.blogcomments.author.requires = IS_NOT_EMPTY()
db.blogcomments.comment.requires = IS_NOT_EMPTY()
db.blogcomments.email.requires = IS_EMAIL()
db.blogcomments.blog_id.requires = IS_IN_DB(db, db.blogpost.id, '%
(title)s')

db.define_table('image',Field('title'),Field('description','text'),Field('file','upload'),Field('blog_id',db.blogpost))
db.image.title.requires = IS_NOT_IN_DB(db, db.image.title)
db.image.blog_id.requires = IS_IN_DB(db, db.blogpost.id, '%(title)s')


controlers :

def index():
   blogpost=db().select(db.blogpost.ALL,orderby=~db.blogpost.datetime)
 
comment=db(db.blogcomments.blog_id==db.blogpost.id).select(db.image.ALL)
   images=db().select(
        db.image.ALL, db.blogpost.ALL,
        left=db.image.on(db.blogpost.id==db.image.blog_id))

   return dict(blogpost=blogpost,comments=comment,images= images)
def show():
 
comments=db(db.blogcomments.blog_id==request.args(0)).select(db.blogcomments.ALL)

 
blogpost=db(db.blogpost.id==request.args(0)).select(db.blogpost.ALL,orderby=~db.blogpost.datetime)
  return dict(comments=comments,blogpost=blogpost)

view :
{{extend 'layout.html'}}

{{=crud.create(db.blogpost)}}
{{=crud.create(db.image)}}
</br>
</br>
{{for blog in blogpost:}}
<h2>{{=blog.title}}</h2>
<div>{{=blog.post}}
{{for pic in images:}}

<div><img width="200px"
     src="{{=URL('download', args=pic.image.file)}}" /></div>

{{pass}}

</br>
<ul>
<li>{{=blog.author}}</li>
<li>{{=blog.datetime}}</li>
<li>{{=A('comment',_href=URL("show", args=blog.id))}}</li>
{{db(db.blogcomments.comment).count()}}</li>
</ul>




</div>
{{pass}}



........................................
it still gets me the same image for all the posts i make.

regards ,

Reply via email to