from django import template from awwca.stockphoto.models import Photo def allowed(pic): if pic.gallery.slug != u'our-communitys-preschools': return True return False register = template.Library() @register.inclusion_tag('stockphoto/random_thumbnail.html') def random_thumbnail(): allowed_pic = False #try: while not allowed_pic: pic = Photo.objects.order_by('?')[0] if allowed(pic): allowed_pic = True #except : # pic = '' return {'picture':pic} @register.inclusion_tag('stockphoto/random_fullsize.html') def random_fullsize(): allowed_pic = False try: while not allowed_pic: pic = Photo.objects.order_by('?')[0] if allowed(pic): allowed_pic = True except: pic = '' return {'picture':pic}