this is the code for adding an image to a blog : when i use it it gets all the images to all the blogs ........................................................... db.py:
import datetime now=datetime.datetime.today() db.define_table('blogposts', SQLField('title', length=64), SQLField('author', default=session.username), SQLField('datetime', 'datetime',default=now), SQLField('post', 'text'), SQLField('numcomments', 'integer',default=0)) db.blogposts.title.requires = [IS_NOT_EMPTY(), IS_NOT_IN_DB(db,db.blogposts.title)] db.blogposts.author.requires = IS_NOT_EMPTY() db.blogposts.post.requires = IS_NOT_EMPTY() db.define_table('image',Field('blog_id',db.blogposts),Field('title'),Field( 'discription','text'),Field('image','upload')) db.image.title.requires = IS_NOT_IN_DB(db, db.image.title) db.image.blog_id.requires = IS_IN_DB(db, db.blogposts.id, '% (title)s') ......................................................................... controler: blogposts = db().select(db.blogposts.ALL, orderby=~db.blogposts.datetime) blogposts_numcomments = db().select(db.blogposts.ALL, orderby=~db.blogposts.numcomments|~db.blogposts.datetime) commentsnposts = db(db.blogcomments.blogpost_id == db.blogposts.id) comments = commentsnposts.select(db.blogcomments.author, db.blogcomments.blogpost_id, db.blogposts.title, orderby=~db.blogcomments.datetime) images=db(db.image.blog_id==db.blogposts.id).select(db.image.ALL) youtube=db(db.youtube.blog_id==db.blogposts.id).select(db.youtube.ALL) vimo=db(db.vimo.blog_id==db.blogposts.id).select(db.vimo.ALL) return dict(blogposts=blogposts, blogposts_numcomments=blogposts_numcomments, comments=comments,images=images,youtube=youtube,vimo=vimo) ..................................... view: {{for photo in images:}} <div style="width:200px ; margin-left:200px"> <div style="width:200px;margin-left:50px"> <p><b>{{=XML(photo.title)}}</b></p> </div> <img width="200px" src="{{=URL('download', args=photo.image)}}" /> <div style="width:200px;margin-left:50px"> <p>{{=XML(photo.discription)}}</p> </div> <div> {{pass}}