Design - Paprika69/cs329e-idb GitHub Wiki
Trying to set a sets of models that could build many to many relationships between the three main models, the books, the authors and the publisher. Our goal is to make the relationship between books and authors, and the relationship between books and publishers could be two-sides. However, the relationship between the author and the publisher is not so important and we did not form a back and forth relationship between the publishers and the authors.
Data Sources
In our project, the data were provided by our instructor Professor Fares Fraij. This set of data is about hundreds of books. Of each book, the books' the publisher's and the author's information were provided. all information are stored in a json file and we load the json file in our parser.py file to make use of all the data to fill in the empty database.
Data Models
We first create three separate models, which are books, authors and publishers. Of each model, many to many relationships are constructed so that different models could be connected.
Books:
The Books model includes its google id, its title, its isbn, a simple description, corresponding image's url of this book and the publication date of each book.
In addition to that, the Books model has many-to-many relationships with the author model as a book can be written by multiple authors and one author could write many books. This is implemented using the assoication model and these following lines:
association_books_authors = db.Table('books_authors', db.Column('books_id', db.Integer, db.ForeignKey('books.id')), db.Column('authors_id', db.Integer, db.ForeignKey('authors.id')) )
authors = db.relationship('Authors', secondary = association_books_authors, lazy='subquery', backref = db.backref("books", lazy=True))
Meanwhile, a similar one-to-many relationship between books and publishers also exist since one book could be published in different publishers with similar codes.
publishers = db.relationship('Publishers', secondary = association_books_publishers, lazy='subquery', backref = db.backref("books", lazy=True))
Authors:
The Authors model includes the author's born time, name, education background (if recorded), nationality, alma_mater and also the link to wikipedia and author's image's link.
In addition to that, the Authors model has a one-to-many relationships with the publisher model as an author can publish books in different publishers. This is implemented using the association model and these following lines:
association_authors_publishers = db.Table('authors_publishers', db.Column('authors_id', db.Integer, db.ForeignKey('authors.id')), db.Column('publishers_id', db.Integer, db.ForeignKey('publishers.id')) )
publishers = db.relationship('Publishers', secondary = association_authors_publishers, lazy='subquery', backref = db.backref("authors", lazy=True))
Publishers:
The Publisher model includes the publisher's name, when it was founded, its location, a brief description, the publisher's parent company and its website.
Unit Test
.
.
