peewee Documentation Release 3.0.0people and how many pets they have: for person in Person.select(): print person.name, person.pets.count(), 'pets' # prints: # Bob 2 pets # Grandma L. 0 pets # Herb 1 pets Once again we’ve run into a classic a SQL function to aggregate the results. query = (Person .select(Person, fn.COUNT(Pet.id).alias('pet_count')) .join(Pet, JOIN.LEFT_OUTER) # include people without pets. .group_by(Person) order_by(Person.name)) for person in query: # "pet_count" becomes an attribute on the returned model instances. print person.name, person.pet_count, 'pets' # prints: # Bob 2 pets # Grandma L. 0 pets0 码力 | 319 页 | 361.50 KB | 1 年前3
peewee Documentation
Release 3.5.0people and how many pets they have: for person in Person.select(): print(person.name, person.pets.count(), 'pets') # prints: # Bob 2 pets # Grandma L. 0 pets # Herb 1 pets Once again we’ve run into a a SQL function to aggregate the results. query = (Person .select(Person, fn.COUNT(Pet.id).alias('pet_count')) .join(Pet, JOIN.LEFT_OUTER) # include people without pets. .group_by(Person) order_by(Person.name)) for person in query: # "pet_count" becomes an attribute on the returned model instances. print(person.name, person.pet_count, 'pets') # prints: # Bob 2 pets # Grandma L. 0 pets0 码力 | 347 页 | 380.80 KB | 1 年前3
peewee Documentation
Release 3.5.0people and how many pets they have: for person in Person.select(): print(person.name, person.pets.count(), 'pets') # prints: # Bob 2 pets # Grandma L. 0 pets # Herb 1 pets Once again we’ve run into a select(Person, fn.COUNT(Pet.id).alias('pet_count')) .join(Pet, JOIN.LEFT_OUTER) # include people without pets. .group_by(Person) .order_by(Person.name)) for person in query: # "pet_count" becomes an attribute attribute on the returned model instances. print(person.name, person.pet_count, 'pets') # prints: # Bob 2 pets # Grandma L. 0 pets # Herb 1 pets Now let’s list all the people and the names of all their0 码力 | 282 页 | 1.02 MB | 1 年前3
peewee Documentation Release 3.4.0people and how many pets they have: for person in Person.select(): print(person.name, person.pets.count(), 'pets') # prints: # Bob 2 pets # Grandma L. 0 pets # Herb 1 pets Once again we’ve run into a a SQL function to aggregate the results. query = (Person .select(Person, fn.COUNT(Pet.id).alias('pet_count')) .join(Pet, JOIN.LEFT_OUTER) # include people without pets. .group_by(Person) order_by(Person.name)) for person in query: # "pet_count" becomes an attribute on the returned model instances. print(person.name, person.pet_count, 'pets') # prints: # Bob 2 pets # Grandma L. 0 pets0 码力 | 349 页 | 382.34 KB | 1 年前3
peewee Documentation
Release 3.4.0people and how many pets they have: for person in Person.select(): print(person.name, person.pets.count(), 'pets') # prints: # Bob 2 pets # Grandma L. 0 pets # Herb 1 pets Once again we’ve run into a select(Person, fn.COUNT(Pet.id).alias('pet_count')) .join(Pet, JOIN.LEFT_OUTER) # include people without pets. .group_by(Person) .order_by(Person.name)) for person in query: # "pet_count" becomes an attribute attribute on the returned model instances. print(person.name, person.pet_count, 'pets') # prints: # Bob 2 pets # Grandma L. 0 pets # Herb 1 pets Now let’s list all the people and the names of all their0 码力 | 284 页 | 1.03 MB | 1 年前3
peewee Documentation
Release 3.3.0people and how many pets they have: for person in Person.select(): print(person.name, person.pets.count(), 'pets') # prints: # Bob 2 pets # Grandma L. 0 pets # Herb 1 pets Once again we’ve run into a select(Person, fn.COUNT(Pet.id).alias('pet_count')) .join(Pet, JOIN.LEFT_OUTER) # include people without pets. .group_by(Person) .order_by(Person.name)) for person in query: # "pet_count" becomes an attribute attribute on the returned model instances. print(person.name, person.pet_count, 'pets') # prints: # Bob 2 pets # Grandma L. 0 pets # Herb 1 pets Now let’s list all the people and the names of all their0 码力 | 280 页 | 1.02 MB | 1 年前3
peewee Documentation Release 3.1.0people and how many pets they have: for person in Person.select(): print(person.name, person.pets.count(), 'pets') # prints: # Bob 2 pets # Grandma L. 0 pets # Herb 1 pets Once again we’ve run into a a SQL function to aggregate the results. query = (Person .select(Person, fn.COUNT(Pet.id).alias('pet_count')) .join(Pet, JOIN.LEFT_OUTER) # include people without pets. .group_by(Person) order_by(Person.name)) for person in query: # "pet_count" becomes an attribute on the returned model instances. print(person.name, person.pet_count, 'pets') # prints: # Bob 2 pets # Grandma L. 0 pets0 码力 | 332 页 | 370.77 KB | 1 年前3
peewee Documentation Release 3.6.0people and how many pets they have: for person in Person.select(): print(person.name, person.pets.count(), 'pets') # prints: # Bob 2 pets # Grandma L. 0 pets # Herb 1 pets Once again we’ve run into a a SQL function to aggregate the results. query = (Person .select(Person, fn.COUNT(Pet.id).alias('pet_count')) .join(Pet, JOIN.LEFT_OUTER) # include people without pets. .group_by(Person) order_by(Person.name)) for person in query: # "pet_count" becomes an attribute on the returned model instances. print(person.name, person.pet_count, 'pets') # prints: # Bob 2 pets # Grandma L. 0 pets0 码力 | 377 页 | 399.12 KB | 1 年前3
peewee Documentation
Release 3.6.0people and how many pets they have: for person in Person.select(): print(person.name, person.pets.count(), 'pets') # prints: # Bob 2 pets # Grandma L. 0 pets # Herb 1 pets Once again we’ve run into a select(Person, fn.COUNT(Pet.id).alias('pet_count')) .join(Pet, JOIN.LEFT_OUTER) # include people without pets. .group_by(Person) .order_by(Person.name)) for person in query: # "pet_count" becomes an attribute attribute on the returned model instances. print(person.name, person.pet_count, 'pets') # prints: # Bob 2 pets # Grandma L. 0 pets # Herb 1 pets 1.2. Quickstart 9 peewee Documentation, Release 3.6.00 码力 | 302 页 | 1.02 MB | 1 年前3
peewee Documentation
Release 2.10.2to Peewee . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 82 1.14 API Reference . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 154 some info about their pets: >>> for person in Person.select(): ... print person.name, person.pets.count(), 'pets' ... for pet in person.pets: ... print ' ', pet.name, pet.animal_type ... Bob 2 pets the records: >>> subquery = Pet.select(fn.COUNT(Pet.id)).where(Pet.owner == Person.id) >>> query = (Person ... .select(Person, Pet, subquery.alias('pet_count')) ... .join(Pet, JOIN.LEFT_OUTER) ... .order_by(Person0 码力 | 221 页 | 844.06 KB | 1 年前3
共 16 条
- 1
- 2













