forked from lucky/autumn
-
Notifications
You must be signed in to change notification settings - Fork 1
How To
bondgeek edited this page Aug 21, 2011
·
7 revisions
This section is for recipes illustrating how-to use autumn.
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)
);
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