library: Redo the model
First shot in library and stock consolidation. Based on @bochecha work.
@bochecha here what I've added on your commit (needed to amend it because I needed to affect the migration dependencies):
- one book can have more than one specimen, so we loop over the books in the data migration instead of looping over the specimens
- from the book detail page, we need to loop through BookSpecimen instances, not Specimen, so we can access the
BookSpecimen.file
and such - in the stock, we don't want the
digital
specimens to appear (no mean to inventory them); that one was tricky: we need to be able from the parent (Stock/Specimen) to be able to filter out some rows according to children properties (only BookSpecimen knows it's a digital specimen); the only option I found is to have a genericphysical
property on the parent, that is always True by default, but that can be then overrided by the children according to it's own behaviour - in the stock, we don't want books with only digital specimens to appear (we may, and will, have books with both physical and digital specimens): another tricky one. What I ended with is making the
StockItem.module
property nullable: item with no module does not appear in the stock; and then on the Book side, at save time, setmodule=None
when the book is in the digital section
There is still some friction in the air:
- we can still add a book from the stock, and doing such this book will only be an item, it will never appear in the library, it will not have any of the book specific properties, etc.
- when editing a book item from the stock, we use the StockItem form, not the Book form, which may be a bit confusing (but even if we found a way to load the book form, there is some tricky behaviour around: when saving a stockitem, we are redirected to the stock page with the stockitem anchor, which behaviour we will not add to the book form view…)
@bochecha: If you have a bit of time to review my changes, that would be really helpful! :)