librelist archives

« back to archive

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

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

From:
Igor Natd
Date:
2012-09-14 @ 22:41
Nope, maybe i did something wrong, but
r = [ Tag for t in db.session.query(Tag).order_by(Tag.name)]return list of
[<class 'app.posts.models.Tag'>] looks good, but if i try get name field  
r[0].name or r[0].idthis return me 
<sqlalchemy.orm.attributes.InstrumentedAttribute object at 0x03228830>>>> 
tags= []>>> t = db.session.query(Tag).order_by(Tag.name)>>> for tag in 
t:...     tags.append(tag)
>>>tagsreturn me list of tags [<Tag: name: u'python'>]>>> 
tags[0].namereturn me as expected - u'python'
Work fine, but your example much more elegant. Thanks!Date: Sat, 15 Sep 
2012 07:38:37 +1000
From: mnbbrown@gmail.com
Subject: Re: [flask] Tag Cloud - How pass list of t ags in each   request‏
To: flask@librelist.com


                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 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.htm
 l can render it? Any decoratoror some else best practise.If you have some
examples will be nice!Thanx all! 		 	   		 
  
  

                 
                 
                 
                 
                
                 
                
                    

                 		 	   		  

unsubscribe

From:
juliobrisomontiano
Date:
2012-09-15 @ 09:17

      
        

Re: [flask] unsubscribe

From:
Gaurav
Date:
2012-09-18 @ 05:25
On Saturday 15 September 2012 02:47 PM, juliobrisomontiano wrote: