librelist archives

« back to archive

Tag Cloud - How pass list of t ags in each request‏

Tag Cloud - How pass list of t ags in each request‏

From:
Igor Natd
Date:
2012-09-14 @ 21:28
Hi Folks!I have simple implementation of tags.table of poststable of 
tagsand many-to-many helper table - post_tags.So i can query - >>>tags = 
db.session.query(Tag).order_by(Tag.name)>>> for r in tags:...        print
r<Tag: name: u'python'>But tags now belongs to type - 
<sqlalchemy.orm.query.Query object at 0x02CE4270>How i can convert it to 
List?And second main question, how i can pass this list of tags in each 
request, that base.html can render it? Any decoratoror some else best 
practise.If you have some examples will be nice!Thanx all! 		 	   		  

Re: [flask] Tag Cloud - How pass list of t ags in each request‏

From:
Matthew Brown
Date:
2012-09-14 @ 21:38
To answer your first question, can you do something like this:

tags = [ tag.name for tag in db.session.query(Tag).order_by(Tag.name) ]

That should convert it to a list.

Cheers,
Matt


On Saturday, 15 September 2012 at 7:28 AM, Igor Natd wrote:

> Hi Folks!
> I have simple implementation of tags.
> table of posts
> table of tags
> and many-to-many helper table - post_tags.
> 
> So i can query - 
> >>>tags = db.session.query(Tag).order_by(Tag.name (http://Tag.name))
> >>> for r in tags:
> ...        print r
> <Tag: name: u'python'>
> But tags now belongs to type - <sqlalchemy.orm.query.Query object at 0x02CE4270>
> How i can convert it to List?
> 
> And second main question, how i can pass this list of tags in each 
request, that base.htm l can render it? Any decorator
> or some else best practise.
> 
> If you have some examples will be nice!
> 
> Thanx all! 

Re: [flask] Tag Cloud - How pass list of t ags in each request‏

From:
Daniel Arbanas
Date:
2012-09-14 @ 21:46
> And second main question, how i can pass this list of tags in each
> request, that base.htm l can render it? Any decorator
> or some else best practise.
>

 http://flask.pocoo.org/docs/templating/#context-processors

-- 
Daniel