__all__ = ['Author', 'Book', 'Extension', 'Genre', 'Language',
'AuthorBook', 'BookGenre',
- 'init_db', 'insert_name', 'update_counters',
+ 'init_db', 'insert_name', 'insert_author', 'update_counters',
]
import os
class Author(SQLObject):
- name = UnicodeCol(notNull=True, unique=True)
+ surname = UnicodeCol(notNull=True)
+ name = UnicodeCol(notNull=True)
+ misc_name = UnicodeCol(notNull=True)
count = IntCol(notNull=True)
books = RelatedJoin('Book', otherColumn='book_id',
intermediateTable='author_book',
createRelatedTable=False)
+ full_name_idx = DatabaseIndex(surname, name, misc_name, unique=True)
count_idx = DatabaseIndex(count)
return table(name=name, count=0, **kw)
+def insert_author(surname, name, misc_name):
+ try:
+ return Author.full_name_idx.get(
+ surname=surname, name=name, misc_name=misc_name)
+ except SQLObjectNotFound:
+ return Author(surname=surname, name=name, misc_name=misc_name, count=0)
+
+
def update_counters():
for author in Author.select():
author.count = len(author.books)