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.