restho.blogg.se

Pony town commands list
Pony town commands list










You may notice that the entity got one extra attribute named id. > show ( Person ) class Person(Entity): id = PrimaryKey(int, auto=True) name = Required(str) age = Required(int) cars = Set(Car) Pass the entity class or the entity instance to this function for printing out the definition: If you need to check an entity definition in the interactive mode, you can use the show() function. We recommend using the str type for string attributes, because it looks more natural in Python 3. Starting with the Pony Release 0.6, you can use either str or unicode for string attributes, both of them mean an unicode string. Python 2 has two types for strings - str and unicode. The str type is used for representing an unicode string in Python 3. Pony creates the intermediate database table automatically. If we need to create a many-to-many relationship between two entities, we should declare two Set attributes at both ends. Relationships in Pony are always defined by two attributes which represent both sides of a relationship. The Car entity has three mandatory attributes: make and model are strings, and the owner attribute is the other side of the one-to-many relationship. "Car" is specified as a string here because we didn’t declare the entity Car by that moment yet.

pony town commands list

It can keep a collection of instances of the Car entity. The cars attribute is declared as Set and has the Car type. The name is a string attribute, while age is numeric. In other words, these attributes cannot have the None value. The name and age are mandatory attributes. Inside the entity Person we have created three attributes – name, age and cars. With Pony you can work with several databases at the same time, but each entity belongs to one specific database. The entity instances are stored in the database, which is bound to the db variable. It means that they are not ordinary classes, but entities.

pony town commands list

The classes that we have created are derived from the Database.Entity attribute of the Database object.












Pony town commands list