Posts Tagged ‘rss’

BibleFeed Project: Creating the models

Thursday, January 29th, 2009

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.

Introducing the BibleFeed project

Friday, January 9th, 2009

I’m definitely a creature of habit. I often tell myself I need to read the bible more, so I could actually know something about my faith. I haven’t been doing this because it has been difficult I never bothered to put it into my routine. I figure if I can integrate the bible with something I read everyday, like Google Reader, I may actually accomplish something instead of just setting up yet another abstract desire in my mind without a plan of action.

The idea for this project is simple. Create an RSS feed of verses from the bible which I can add to Google Reader or any other feed reader. If I read a chapter a day, then over time (around 3 years) I will have read the entire bible.

I’ll admit that there’s another purpose here. I want to practice development with Django and Python. This is not my first Django project. Ok, it’s my second, but the first project is something that a friend and I are slowly working on that I can’t talk about yet.

Just like most software developers, documentation is a weakness of mine, so I will be documenting this project as I go. This helps me practice writing and documentation, and helps you if you have any interest in Django or just how to go about creating an RSS feed of the bible.

On a technical note, I am using Linux, but this can be done with Windows and Mac OS X as well. The steps may vary slightly for those operating systems.

The first place to start is to actually create the project. The steps I’m using will mostly follow along with the official Django tutorial. See http://docs.djangoproject.com/en/dev/intro/tutorial01/.

django-admin.py startproject biblefeed

Create the database, which I’m calling “biblefeed”. I’m using PostgreSQL and the command that follows will be different if you use a different database backend.

createdb -E UTF8 -U postgres biblefeed

Edit the settings.py to match your database settings:

DATABASE_ENGINE = ‘postgresql’
DATABASE_NAME = ‘biblefeed’
DATABASE_USER = ‘postgres’
DATABASE_PASSWORD = ‘xxxxxxxx’

Sync the database to setup default tables and create a super user when prompted.

python manage.py syncdb

Create the application.

python manage.py startapp bible

At this point I will add the project to my subversion repository. You do use a version control system, right?

In the next article I will create the models I need to store bible verses in the database.