Skip to content
bondgeek edited this page Aug 21, 2011 · 7 revisions

This section is for recipes illustrating how-to use autumn.

Sample Database

Examples assume the following simple mysql database.

CREATE TABLE author (
   id INT(11) NOT NULL auto_increment,
   first_name VARCHAR(40) NOT NULL,
   last_name VARCHAR(40) NOT NULL,
   bio TEXT,
   PRIMARY KEY (id)
   );

CREATE TABLE books (
  id INT(11) NOT NULL auto_increment,
  title VARCHAR(255),
  author_id INT(11),
  FOREIGN KEY (author_id) REFERENCES author(id),
  PRIMARY KEY (id)
  );

Relations: OneToMany, Foreign Keys

The foreign key defines a link, such as for a reference table.

class Author(Model):
    books = OneToMany('Book')
    
class Books(Model):
    author = ForeignKey('Author')
    
    @property
    def author_bio(self):
        return self.author.bio
Clone this wiki locally