In fact, we just need to customize the query a little bit

10Окт

In fact, we just need to customize the query a little bit

If you find yourself familiar with SQL, you could remember that one may Select from numerous dining tables, making it possible for me to obtain the tweet content together with login name into the just one query:

Peewee makes it very easy. I share with Peewee we wish to see Tweet.blogs and the Member kupon mingle2.username career, then i were a join from tweet to help you member. Making it more noticeable that it’s performing the new best situation, we can inquire Peewee to return brand new rows because dictionaries.

Today we will get off off the telephone call in order to “.dicts()” and you may come back new rows since Tweet objects. Observe that Peewee assigns the username really worth so you’re able to tweet.representative.login name – Maybe not tweet.login name ! While there is a foreign-trick of tweet so you’re able to affiliate, and then we have chosen sphere away from each other patterns, Peewee often reconstruct the latest model-graph for us:

When we desire to, we could control in which Peewee places the fresh new registered Representative such as for example inside the the aforementioned inquire, by specifying an enthusiastic attr throughout the register() method:

On the other hand, when we just wish to all of the functions i see as properties of your Tweet for example, we are able to create a call so you can stuff() at the end of all of our ask (the same as how exactly we named dicts() ):

×