Created
August 11, 2008 19:59
-
-
Save lizadaly/4929 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class LibraryItem(models.Model): | |
owner = models.ForeignKey(Member) | |
class Status(models.Model): | |
name = models.CharField(max_length=50) | |
class ItemStatus(models.Model): | |
item = models.ForeignKey(LibraryItem) | |
status = models.ForeignKey(Status) | |
# Somewhere in the app at startup you initialize all the statuses: | |
all_statuses = ('I own this', "I've read this", "I've played this") | |
book_statuses = (all_statuses[0], all_statuses[1]) | |
game_statuses = (all_statuses[0], all_statuses[2]) | |
allowed_in_book = [] | |
for status in all_statuses: | |
s = Status(status) | |
s.save() | |
for status in book_statuses: | |
s = Status.objects.get(name=status) | |
allowed_in_book.append(s) | |
# Now allowed_in_book is the list of status objects that we use to pull | |
# the dropdown lists from and check before saving | |
# Each time the user updates a status, you add or delete an ItemStatus object | |
# To extend this to 'reading (with current page stored as well)' or | |
# similar model-specific objects, I would just create another model object | |
# in the same way: | |
class ReadingCurrentPage(models.Model): | |
status = models.ForeignKey(ItemStatus) | |
current_page = models.IntegerField() | |
# However, if you are really really expecting zillions of users, highly | |
# normalized schemas like this don't scale well. The best thing in that | |
# case is to be really ugly, and go back to your original model, but just | |
# keep extending it: | |
own = models.BooleanField(default=False, db_index=True) | |
used = models.BooleanField(default=False, db_index=True) | |
current = models.BooleanField(default=False, db_index=True) | |
want = models.BooleanField(default=False, db_index=True) | |
watching = models.BooleanField(default=False, db_index=True) | |
top = models.BooleanField(default=False, db_index=True) | |
seen_in_theaters = models.BooleanField(default=False, db_index=True) | |
# achievements_unlocked, Actually get this from the XBL API! | |
# I wouldn't really suggest it though -- you'd have to be getting | |
# Facebook-level hits to make it worth the maintability headaches |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment