BibleFeed Project: Creating the models

This is the second post relating to the BibleFeed Project. If you haven’t yet, you may want to read the first post.

As with most applications, this one needs to store data. To store data in a django project, I need to first create models representing the data. While I’m sure that the following will not be everything, this is good enough to start with:

class Book(models.Model):
    TESTAMENTS = (
        ('O','Old Testament'),
        ('N','New Testament'),
    )
    name = models.CharField(max_length=50)
    testament = models.CharField(max_length=1, choices=TESTAMENTS)
   
class Chapter(models.Model):
    book = models.ForeignKey(Book)
    chapter_num = models.IntegerField()
   
class Verse(models.Model):
    chapter = models.ForeignKey(Chapter)
    text = models.TextField()
    verse_num = models.IntegerField()

These models are straightforward. There is a Book class which will store the name of book and which testament it is part of. The Chapter class has a field storing which book it is part of, and a field for the chapter number. The Verse class points to the chapter that contains it and has fields for the text of the verse and the verse number.
Now I need to have somewhere to store the data now that I have the models to represent it. Before I do that though, I need to let django know it should include the BibleFeed application. I edit the INSTALLED_APPS setting in the settings.py field:

INSTALLED_APPS = (
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.sites',
    'biblefeed.bible',
)

Now I can run the syncdb command which will create the database tables.

$ python manage.py syncdb
Creating table bible_book
Creating table bible_chapter
Creating table bible_verse
Installing index for bible.Chapter model
Installing index for bible.Verse model

I realize at this point I haven’t shown anything too exciting, and there’s not much that is interactive here, unless you really enjoy viewing the tables in the database. The next post will create something a little more interactive.

Tags: , , , ,

2 Responses to “BibleFeed Project: Creating the models”

  1. Thomas (babelhut.com) Says:

    Just an idea, but you may want to expand to allow for the Apocrypha. They aren’t considered Christian canon, but I think most Bible readers would have at least a peripheral interest in those books. You’d want to mark them clearly as Apocryphal if you did of course. You could have checkboxes or something to turn them on or off at the RSS subscribe stage. Or maybe just make a separate ApocryphaFeed later. Anyway, just thought I’d throw that out there.

  2. peter Says:

    For this project I was intending to keep it simple, but in the future there’s no reason I couldn’t add a feed for Apocryphal texts.