Simple loan system for library

36 views
Skip to first unread message

john smith

unread,
May 23, 2014, 5:30:35 PM5/23/14
to web...@googlegroups.com
I'm trying to create library system and have a little problem. Here's my current model:
db.define_table('tags', 
Field('name'),format='%(name)s') 
db.define_table('copies',
    Field('is_active','boolean',default=True))

db.define_table('book',
Field('title',requires=IS_NOT_EMPTY(), label='Tytuł'),
Field('author', requires=IS_NOT_EMPTY(), label='Autor'),
Field('isbn', 'integer', requires=IS_LENGTH(13), label='ISBN'),
Field('release_year', 'integer', requires=IS_INT_IN_RANGE(-3000, request.utcnow.year+1), label='Rok wydania'),
Field('format', label='Format'),
Field('cover', 'upload', requires = IS_EMPTY_OR(IS_IMAGE()), label='Okładka'),
Field('publisher', label='Wydawca'),
Field('tags', 'list:reference tags', label='Tagi'), 
Field('copies', db.copies),
auth.signature)

db.book.tags.widget = SQLFORM.widgets.checkboxes.widget

Here is what I want to achieve: when a user adds new 'book' table record, he types number of copies of that book and that amount of records is automatically created in 'copies' table. Then a user will be able to loan a specific copy of a book (i will probably be able to figure this part out thanks to library example) but only for specific period. If you have other ideas on how to solve my problem, please share.
Also less important but i would like to change the style of my tags widget, so it would display either set number of tags per row or just display maximum number that will fit in screen.
Thanks in advance for all replies.

Andrew W

unread,
May 23, 2014, 10:51:00 PM5/23/14
to web...@googlegroups.com
Hi John,
One step at a time, looking at your database model,  how does 'copies' relate to a book ?  You are missing a foreign key reference.   Are there any other attributes that a copy may have ?

john smith

unread,
May 24, 2014, 7:25:28 AM5/24/14
to web...@googlegroups.com
I'm very new to this, so I'm not sure if I understand the 'foreign key' concept, but from what I understand
Field('copies', db.copies),
would be my foreign key reference. Now that i thought about it, it should probably go the other way since I want one book to have many copies. But I would still like to create many copies while creating a book and while modifying it. 
If by attributes you mean fields then it will probably get attribute like 'state' that will describe whether the copy was damaged or lost, and it might get something else but nothing comes to my mind right now. If that is not what you meant, then I have no idea. 
I should add that this is a school project so I can change it pretty much any way I like it. If you have better idea on how to create renting system then please do tell.
Reply all
Reply to author
Forward
0 new messages