Developer Interface
Models
This part of the documentation covers all the models provided by django-book-manager.
Books
- class book_manager.models.Book(id, created, modified, title, slug, isbn, isbn13, num_pages, year_published, original_publication_year, binding, publisher)[source]
Database table:
book_manager_book- Parameters
id (AutoField) – Primary key: ID
created (CreationDateTimeField) – Created
modified (ModificationDateTimeField) – Modified
title (CharField) – Book Title. The title of the book
slug (AutoSlugField) – Slug. Used in the URL for the book. Must be unique.
isbn (CharField) – ISBN
isbn13 (CharField) – ISBN
num_pages (PositiveIntegerField) – Num Pages
year_published (IntegerField) – Year Published
original_publication_year (IntegerField) – Original Publication Year
Relationship fields:
- Parameters
binding (
ForeignKeytoBinding) – Binding (related name:books)publisher (
ForeignKeytoPublisher) – Publisher (related name:books)authors (
ManyToManyFieldtoAuthor) – Authors (related name:books)readers (
ManyToManyFieldtoUser) – Readers (related name:books)
Reverse relationships:
- Parameters
bookauthor (Reverse
ForeignKeyfromBookAuthor) – All book authors of this book (related name ofbook)readings (Reverse
ForeignKeyfromReading) – All readings of this book (related name ofbook)
- exception DoesNotExist
- exception MultipleObjectsReturned
- get_next_by_created(*, field=<django_extensions.db.fields.CreationDateTimeField: created>, is_next=True, **kwargs)
Finds next instance based on
created. Seeget_next_by_FOOfor more information.
- get_next_by_modified(*, field=<django_extensions.db.fields.ModificationDateTimeField: modified>, is_next=True, **kwargs)
Finds next instance based on
modified. Seeget_next_by_FOOfor more information.
- get_previous_by_created(*, field=<django_extensions.db.fields.CreationDateTimeField: created>, is_next=False, **kwargs)
Finds previous instance based on
created. Seeget_previous_by_FOOfor more information.
- get_previous_by_modified(*, field=<django_extensions.db.fields.ModificationDateTimeField: modified>, is_next=False, **kwargs)
Finds previous instance based on
modified. Seeget_previous_by_FOOfor more information.
- authors: ManyToManyField
Type:
ManyToManyFieldtoAuthorAuthors (related name:
books)Accessor to the related objects manager on the forward and reverse sides of a many-to-many relation.
In the example:
class Pizza(Model): toppings = ManyToManyField(Topping, related_name='pizzas')
Pizza.toppingsandTopping.pizzasareManyToManyDescriptorinstances.Most of the implementation is delegated to a dynamically defined manager
- binding: ForeignKey
Type:
ForeignKeytoBindingBinding (related name:
books)Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.
In the example:
class Child(Model): parent = ForeignKey(Parent, related_name='children')
- bookauthor_set
Type: Reverse
ForeignKeyfromBookAuthorAll book authors of this book (related name of
book)Accessor to the related objects manager on the reverse side of a many-to-one relation.
In the example:
class Child(Model): parent = ForeignKey(Parent, related_name='children')
Parent.childrenis aReverseManyToOneDescriptorinstance.Most of the implementation is delegated to a dynamically defined manager
- created
Type:
CreationDateTimeFieldCreated
A wrapper for a deferred-loading field. When the value is read from this
- id
Type:
AutoFieldPrimary key: ID
A wrapper for a deferred-loading field. When the value is read from this
- isbn: Field
Type:
CharFieldISBN
A wrapper for a deferred-loading field. When the value is read from this
- isbn13: Field
Type:
CharFieldISBN
A wrapper for a deferred-loading field. When the value is read from this
- modified
Type:
ModificationDateTimeFieldModified
A wrapper for a deferred-loading field. When the value is read from this
- num_pages: Field
Type:
PositiveIntegerFieldNum Pages
A wrapper for a deferred-loading field. When the value is read from this
- objects = <django.db.models.Manager object>
- original_publication_year: Field
Type:
IntegerFieldOriginal Publication Year
A wrapper for a deferred-loading field. When the value is read from this
- property other_authors: QuerySet
Return all authors other than the top-billed author for this book. These are the authors with
order>1in ourBookAuthorthrough table.- Returns
The queryset of
Authorobjects for the non-primary author.
- property primary_author: Author
Return the top-billed author for this book. This is the author with
order=1in ourBookAuthorthrough table.- Returns
The
Authorobject for the primary author
- publisher: ForeignKey
Type:
ForeignKeytoPublisherPublisher (related name:
books)Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.
In the example:
class Child(Model): parent = ForeignKey(Parent, related_name='children')
- readers: ManyToManyField
Type:
ManyToManyFieldtoUserReaders (related name:
books)Accessor to the related objects manager on the forward and reverse sides of a many-to-many relation.
In the example:
class Pizza(Model): toppings = ManyToManyField(Topping, related_name='pizzas')
Pizza.toppingsandTopping.pizzasareManyToManyDescriptorinstances.Most of the implementation is delegated to a dynamically defined manager
- readings
Type: Reverse
ForeignKeyfromReadingAll readings of this book (related name of
book)Accessor to the related objects manager on the reverse side of a many-to-one relation.
In the example:
class Child(Model): parent = ForeignKey(Parent, related_name='children')
Parent.childrenis aReverseManyToOneDescriptorinstance.Most of the implementation is delegated to a dynamically defined manager
- slug: Field
Type:
AutoSlugFieldSlug. Used in the URL for the book. Must be unique.
A wrapper for a deferred-loading field. When the value is read from this
- title: Field
Type:
CharFieldBook Title. The title of the book
A wrapper for a deferred-loading field. When the value is read from this
- year_published: Field
Type:
IntegerFieldYear Published
A wrapper for a deferred-loading field. When the value is read from this
- class book_manager.models.Author(*args, **kwargs)[source]
Database table:
book_manager_authorAn author of a
Book. Books can have multiple authors.- Parameters
Reverse relationships:
- Parameters
books (Reverse
ManyToManyFieldfromBook) – All books of this author (related name ofauthors)bookauthor (Reverse
ForeignKeyfromBookAuthor) – All book authors of this author (related name ofauthor)
- exception DoesNotExist
- exception MultipleObjectsReturned
- get_next_by_created(*, field=<django_extensions.db.fields.CreationDateTimeField: created>, is_next=True, **kwargs)
Finds next instance based on
created. Seeget_next_by_FOOfor more information.
- get_next_by_modified(*, field=<django_extensions.db.fields.ModificationDateTimeField: modified>, is_next=True, **kwargs)
Finds next instance based on
modified. Seeget_next_by_FOOfor more information.
- get_previous_by_created(*, field=<django_extensions.db.fields.CreationDateTimeField: created>, is_next=False, **kwargs)
Finds previous instance based on
created. Seeget_previous_by_FOOfor more information.
- get_previous_by_modified(*, field=<django_extensions.db.fields.ModificationDateTimeField: modified>, is_next=False, **kwargs)
Finds previous instance based on
modified. Seeget_previous_by_FOOfor more information.
- bookauthor_set
Type: Reverse
ForeignKeyfromBookAuthorAll book authors of this author (related name of
author)Accessor to the related objects manager on the reverse side of a many-to-one relation.
In the example:
class Child(Model): parent = ForeignKey(Parent, related_name='children')
Parent.childrenis aReverseManyToOneDescriptorinstance.Most of the implementation is delegated to a dynamically defined manager
- books
Type: Reverse
ManyToManyFieldfromBookAll books of this author (related name of
authors)Accessor to the related objects manager on the forward and reverse sides of a many-to-many relation.
In the example:
class Pizza(Model): toppings = ManyToManyField(Topping, related_name='pizzas')
Pizza.toppingsandTopping.pizzasareManyToManyDescriptorinstances.Most of the implementation is delegated to a dynamically defined manager
- created
Type:
CreationDateTimeFieldCreated
A wrapper for a deferred-loading field. When the value is read from this
- first_name: Field
Type:
CharFieldFirst name
A wrapper for a deferred-loading field. When the value is read from this
- full_name: Field
Type:
CharFieldFull name
A wrapper for a deferred-loading field. When the value is read from this
- id
Type:
AutoFieldPrimary key: ID
A wrapper for a deferred-loading field. When the value is read from this
- last_name: Field
Type:
CharFieldLast name
A wrapper for a deferred-loading field. When the value is read from this
- middle_name: Field
Type:
CharFieldMiddle name
A wrapper for a deferred-loading field. When the value is read from this
- modified
Type:
ModificationDateTimeFieldModified
A wrapper for a deferred-loading field. When the value is read from this
- objects = <django.db.models.Manager object>
- class book_manager.models.BookAuthor(*args, **kwargs)[source]
Database table:
book_manager_bookauthorThis is a through table between
BookandAuthorthat allows us to keep our book authors in the correct order.- Parameters
id (AutoField) – Primary key: ID
order (PositiveIntegerField) – Author order
Relationship fields:
- Parameters
book (
ForeignKeytoBook) – Book (related name:bookauthor)author (
ForeignKeytoAuthor) – Author (related name:bookauthor)
- exception DoesNotExist
- exception MultipleObjectsReturned
- author
Type:
ForeignKeytoAuthorAuthor (related name:
bookauthor)Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.
In the example:
class Child(Model): parent = ForeignKey(Parent, related_name='children')
- book
Type:
ForeignKeytoBookBook (related name:
bookauthor)Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.
In the example:
class Child(Model): parent = ForeignKey(Parent, related_name='children')
- id
Type:
AutoFieldPrimary key: ID
A wrapper for a deferred-loading field. When the value is read from this
- objects = <django.db.models.Manager object>
- order
Type:
PositiveIntegerFieldAuthor order
A wrapper for a deferred-loading field. When the value is read from this
- class book_manager.models.Publisher(*args, **kwargs)[source]
Database table:
book_manager_publisherA publisher of a
Book. Books have zero or one publishers.- Parameters
Reverse relationships:
- Parameters
books (Reverse
ForeignKeyfromBook) – All books of this publisher (related name ofpublisher)
- exception DoesNotExist
- exception MultipleObjectsReturned
- get_next_by_created(*, field=<django_extensions.db.fields.CreationDateTimeField: created>, is_next=True, **kwargs)
Finds next instance based on
created. Seeget_next_by_FOOfor more information.
- get_next_by_modified(*, field=<django_extensions.db.fields.ModificationDateTimeField: modified>, is_next=True, **kwargs)
Finds next instance based on
modified. Seeget_next_by_FOOfor more information.
- get_previous_by_created(*, field=<django_extensions.db.fields.CreationDateTimeField: created>, is_next=False, **kwargs)
Finds previous instance based on
created. Seeget_previous_by_FOOfor more information.
- get_previous_by_modified(*, field=<django_extensions.db.fields.ModificationDateTimeField: modified>, is_next=False, **kwargs)
Finds previous instance based on
modified. Seeget_previous_by_FOOfor more information.
- books
Type: Reverse
ForeignKeyfromBookAll books of this publisher (related name of
publisher)Accessor to the related objects manager on the reverse side of a many-to-one relation.
In the example:
class Child(Model): parent = ForeignKey(Parent, related_name='children')
Parent.childrenis aReverseManyToOneDescriptorinstance.Most of the implementation is delegated to a dynamically defined manager
- created
Type:
CreationDateTimeFieldCreated
A wrapper for a deferred-loading field. When the value is read from this
- id
Type:
AutoFieldPrimary key: ID
A wrapper for a deferred-loading field. When the value is read from this
- modified
Type:
ModificationDateTimeFieldModified
A wrapper for a deferred-loading field. When the value is read from this
- name: Field
Type:
CharFieldPublisher name. Publisher name
A wrapper for a deferred-loading field. When the value is read from this
- objects = <django.db.models.Manager object>
- class book_manager.models.Binding(*args, **kwargs)[source]
Database table:
book_manager_bindingA binding of a
Book(“ebook”, “mass market paperback”, “hardcover”, etc.). Books have zero or one bindings.Reverse relationships:
- Parameters
books (Reverse
ForeignKeyfromBook) – All books of this binding (related name ofbinding)
- exception DoesNotExist
- exception MultipleObjectsReturned
- books
Type: Reverse
ForeignKeyfromBookAll books of this binding (related name of
binding)Accessor to the related objects manager on the reverse side of a many-to-one relation.
In the example:
class Child(Model): parent = ForeignKey(Parent, related_name='children')
Parent.childrenis aReverseManyToOneDescriptorinstance.Most of the implementation is delegated to a dynamically defined manager
- id
Type:
AutoFieldPrimary key: ID
A wrapper for a deferred-loading field. When the value is read from this
- name: Field
Type:
CharFieldBinding type. Binding type
A wrapper for a deferred-loading field. When the value is read from this
- objects = <django.db.models.Manager object>
Readings
A Reading is a single person’s use of a Book. It records that
person’s notes, ratings, reading count, etc.
- class book_manager.models.Reading(*args, **kwargs)[source]
Database table:
book_manager_readingThis model holds user-specific data about a reading of a
Book- Parameters
id (AutoField) – Primary key: ID
created (CreationDateTimeField) – Created
modified (ModificationDateTimeField) – Modified
rating (PositiveIntegerField) – Rating
private_notes (TextField) – Private Notes. Private notes that only you can see
review (TextField) – Review. Notes that anyone can see
read_count (PositiveIntegerField) – Read count. How many times you’ve read this book
date_added (DateField) – Date added. Date this book was added to your reading list
date_read (DateField) – Date read. Date you first read this book
Relationship fields:
- Parameters
reader (
ForeignKeytoUser) – Reader (related name:readings)book (
ForeignKeytoBook) – Book (related name:readings)shelf (
ForeignKeytoShelf) – Shelf (related name:readings)
- exception DoesNotExist
- exception MultipleObjectsReturned
- get_next_by_created(*, field=<django_extensions.db.fields.CreationDateTimeField: created>, is_next=True, **kwargs)
Finds next instance based on
created. Seeget_next_by_FOOfor more information.
- get_next_by_date_added(*, field=<django.db.models.DateField: date_added>, is_next=True, **kwargs)
Finds next instance based on
date_added. Seeget_next_by_FOOfor more information.
- get_next_by_modified(*, field=<django_extensions.db.fields.ModificationDateTimeField: modified>, is_next=True, **kwargs)
Finds next instance based on
modified. Seeget_next_by_FOOfor more information.
- get_previous_by_created(*, field=<django_extensions.db.fields.CreationDateTimeField: created>, is_next=False, **kwargs)
Finds previous instance based on
created. Seeget_previous_by_FOOfor more information.
- get_previous_by_date_added(*, field=<django.db.models.DateField: date_added>, is_next=False, **kwargs)
Finds previous instance based on
date_added. Seeget_previous_by_FOOfor more information.
- get_previous_by_modified(*, field=<django_extensions.db.fields.ModificationDateTimeField: modified>, is_next=False, **kwargs)
Finds previous instance based on
modified. Seeget_previous_by_FOOfor more information.
- book
Type:
ForeignKeytoBookBook (related name:
readings)Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.
In the example:
class Child(Model): parent = ForeignKey(Parent, related_name='children')
- created
Type:
CreationDateTimeFieldCreated
A wrapper for a deferred-loading field. When the value is read from this
- date_added
Type:
DateFieldDate added. Date this book was added to your reading list
A wrapper for a deferred-loading field. When the value is read from this
- date_read
Type:
DateFieldDate read. Date you first read this book
A wrapper for a deferred-loading field. When the value is read from this
- id
Type:
AutoFieldPrimary key: ID
A wrapper for a deferred-loading field. When the value is read from this
- modified
Type:
ModificationDateTimeFieldModified
A wrapper for a deferred-loading field. When the value is read from this
- objects = <django.db.models.Manager object>
- private_notes
Type:
TextFieldPrivate Notes. Private notes that only you can see
A wrapper for a deferred-loading field. When the value is read from this
- rating
Type:
PositiveIntegerFieldRating
A wrapper for a deferred-loading field. When the value is read from this
- read_count
Type:
PositiveIntegerFieldRead count. How many times you’ve read this book
A wrapper for a deferred-loading field. When the value is read from this
- reader
Type:
ForeignKeytoUserReader (related name:
readings)Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.
In the example:
class Child(Model): parent = ForeignKey(Parent, related_name='children')
- review
Type:
TextFieldReview. Notes that anyone can see
A wrapper for a deferred-loading field. When the value is read from this
- shelf
Type:
ForeignKeytoShelfShelf (related name:
readings)Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.
In the example:
class Child(Model): parent = ForeignKey(Parent, related_name='children')
- class book_manager.models.Shelf(*args, **kwargs)[source]
Database table:
book_manager_shelfThis model is used to organize
Readinginstances for a user into buckets (“read”, “to-read”, “abandoned”). Shelves are per-user.- Parameters
Relationship fields:
- Parameters
reader (
ForeignKeytoUser) – Reader (related name:shelves)
Reverse relationships:
- Parameters
readings (Reverse
ForeignKeyfromReading) – All readings of this shelf (related name ofshelf)
- exception DoesNotExist
- exception MultipleObjectsReturned
- id
Type:
AutoFieldPrimary key: ID
A wrapper for a deferred-loading field. When the value is read from this
- name: Field
Type:
CharFieldShelf name. Name of a shelf on which books can live
A wrapper for a deferred-loading field. When the value is read from this
- objects = <django.db.models.Manager object>
- reader
Type:
ForeignKeytoUserReader (related name:
shelves)Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.
In the example:
class Child(Model): parent = ForeignKey(Parent, related_name='children')
- readings
Type: Reverse
ForeignKeyfromReadingAll readings of this shelf (related name of
shelf)Accessor to the related objects manager on the reverse side of a many-to-one relation.
In the example:
class Child(Model): parent = ForeignKey(Parent, related_name='children')
Parent.childrenis aReverseManyToOneDescriptorinstance.Most of the implementation is delegated to a dynamically defined manager
Widgets
This part of the documentation covers all the reusable django-wildewidgets widgets provided by
django-book-manager.
Importers
- class book_manager.importers.GoodreadsImporter[source]
Usage:
GoodreadsImporter().run(csv_filename, user)Import data into our database from a Goodreeads CSV Export.
Import any new
book_manager.models.Binding,book_manager.models.Publisher, andbook_manager.models.AuthorinstancesImport the book from each row as a
book_manager.models.BookImport the user specific data from each row as a
book_manager.models.Readingassociated with the useruser
A Goodreads CSV export has these columns:
Column name
Type
Notes
Book Id
int, unique
goodreads internal id
Title
str
Author
str
First Last
Author l-f
str
Last, First
Additional Authors
str
First Last1, First Last2…
ISBN
str
value is “=” if empty
ISBN13
str
value is “=” if empty
My Rating
int
0, 1, 2, 3, 4, 5
Average Rating
float
2 decimals
Publisher
str
can be empty
Binding
str
can be empty
Number of Pages
int
can be empty
Year Published
int
can be empty
Original Publication Year
int
can be empty
Date read
date
YYYY/MM/DD
Date added
date
YYYY/MM/DD
Bookshelves
str
comma separated
Bookshelves with positions
str
NAME (#NUM), comma sep
Exclusive Shelf
str
NAME
My Review
text
can be empty
Spoiler
text
can be empty
Private Notes
text
can be empty
Read count
int
Owned copies
int
- import_book(row: Dict[str, Any], overwrite: bool = False) Book[source]
Get or create a
Bookbased onrow, a row from ourcsv.DictReaderreader of our Goodreads export.- Parameters
row – a row from our Goodreads export
- Keyword Arguments
overwrite – if
True, overwrite any existing book data for this book- Returns
A
Bookinstance
- import_reading(book: Book, user: User, row: Dict[str, Any]) None[source]
Import the data for the
Readingrecord foruser.- Parameters
book – the book for which we’re importing reading data
user – the user whose reading data we’re importing
row – the row from the Goodreads CSV, as output by
csv.DictReader
- load_lookups(filename: str) None[source]
Find the unique bindings, publishers and authors in the Goodreads export CSV
filenameand create them in the database as necessary.- Parameters
filename – the filename of the CSV file to read
- run(filename: str, user: User, overwrite: bool = False) None[source]
Load the books in the CSV identified by
filenameinto the database, splitting each row into appropriatebook_manager.models.Book,book_manager.models.Author,book_manager.models.Publisherandbook_manager.models.Bindingrecords, creating the foreign keys and many-to-many targets as needed.bookmanager.models.Readingdata will always be overwritten, andbookmanager.models.Bookdata will be preserved, unlessoverrideisTrue.- Parameters
filename – the filename of the Goodreads CSV export file
- Keyword Arguments
overwrite – if
True, overwrite any existingBookwith data from the CSV