db.define_table('photoalbum',
Field('reguser_id'),
Field('album_name'),
Field('short_description'),
)
db.define_table(photos',
Field('reguser_id'),
Field('caption'),
Field('category', requires=IS_IN_SET(pix_cat)),
Field('description', 'text'),
Field('upload_photo', 'upload' , uploadfolder=request.folder + 'static/uploads', default=0, autodelete=True,),
Field('album_name', requires=IS_IN_SET(albums)),
)
def myalbums():
## selects all albums
allalbums = db(db.photoalbum.reguser_id == session.logged_in_user_id). select(db.photoalbum.album_name)
# selects descriptions for all albums
alldescriptions = db(db.photoalbum.reguser_id == session.logged_in_user_id). select(db.photoalbum.short_description)
## selects photos
allimages = db(db.photos.reguser_id == session.logged_in_user_id). select(db.photos.upload_photo, db.photos.caption, db.photos.description, cache=(cache.ram,20))
return dict(allalbums=allalbums, alldescriptions=alldescriptions, allimages=allimages)
{{for i in range(len(allalbums)):}}
<ul class="thumbnails">
<!-- Iterate over all images - -->
<li class="span2">
<div class="thumbnail">
<!-- <img data-src="holder.js/300x200" alt="300x200" style=""> -->
{{=(A(IMG(_src=URL(r=request,c='static\images',f='vimage.jpg')),_href=URL (r=request,c='default', f='myalbums', args=[allalbums[i].album_name]) ))}}
<div class="caption">
<h5>{{=allalbums[i].album_name}}</h5>
<p>{{=alldescriptions[i].short_description}}</p>
</div>
</div>
</li>
{{pass}}
{{pass}}
Hi All,
I am writing an image gallery in my app. I am stuck up here -
I want to display images that belong to a particular album when I select that album in the view. Although I am able to display albums in the view, but cannot proceed further to display images belonging to that particular albums after clicking the album (from the view).
here are the table in db.py -db.define_table('photoalbum',
Field('reguser_id'),
Field('album_name'),
Field('short_description'),
)
db.define_table(photos',
Field('reguser_id'),
Field('caption'),
Field('category', requires=IS_IN_SET(pix_cat)),
Field('description', 'text'),
Field('upload_photo', 'upload' , uploadfolder=request.folder + 'static/uploads', default=0, autodelete=True,),
Field('album_name', requires=IS_IN_SET(albums)),
)
I would think you want the last line to be a reference, like Field('album_name', 'reference photoalbum');
Again - The image vimage.jpg specified in the view is a static image, can the thumbnail image representing a particular album be created from an image from within the album ? Please suggest ..
query = (db.fotoz.album_name == "%s" % request.args(0))
<p> <a href="{{=URL(r=request, c='default', f='view_album', args=[allalbums[i].album_name])}}" class="btn">View Album</a></p>
Hi Dave, All,
I found a solution - It was easy -
wrote a new function that takes a parameter, called it in the view and it redirects to the required page.
query = (db.fotoz.album_name == "%s" % request.args(0))
and have this<p> <a href="{{=URL(r=request, c='default', f='view_album', args=[allalbums[i].album_name])}}" class="btn">View Album</a></p>
in view.
That sends the argument to this function and displays the album. The only issue is with spaces in album names that dont work. But I would find a workaround over it.
We can consider this thread closed. Thanks Everyone.
Cheers, Rahul
A few threads that helped... -
https://groups.google.com/forum/#!topic/web2py/WJtJ-QDemTM
http://stackoverflow.com/questions/9328126/web2py-connecting-to-the-correct-controller
https://groups.google.com/forum/#!topic/web2py/ICo5-yFgxmc
On Friday, June 20, 2014 10:24:42 AM UTC+5:30, Rahul wrote: