Then depending of your URL format... You will request the id of your
blogposts table passed in the URL... Of course when you create a new record
in blogposts table there will have no ID since you are creating it.

request.args(1) I guess could containt your blogposts id if your URL looks
like this :

http://127.0.0.1:8000/app/controller/function/table/1

Richard




On Tue, Jul 26, 2011 at 12:28 PM, Richard Vézina <
ml.richard.vez...@gmail.com> wrote:

> images=db(db.image.blog_id==db.blogposts.id).select(db.image.ALL)
>
> Here you are saying to the database to do exactly what you don't want...
>
> You should pass the id of your db.blogposts and not all the ids...
>
> Try :
>
> images=db(db.image.blog_id==1).select(db.image.ALL)
>
> If there is a blogposts that have id 1... You should have only the images
> associates to this blogposts record...
>
> Richard
>
>
> On Tue, Jul 26, 2011 at 12:19 PM, Web2Py Freak <halna...@gardeniatelco.com
> > wrote:
>
>> 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}}
>>
>
>

Reply via email to