Firebird News

Wednesday, September 11, 2013

Django and Firebird support

I have started to read the django book and i could make it work with firebird without issues

Bellow are the instructions for Chapter 2 : Getting started


Install django using pip

pip install django

check django version from python console

>>> import django
>>> django.VERSION
(1, 5, x, 'final', 0)

pip install django-firebird

create a new project
django-admin.py startproject wordpress_clone

cd wordpress_clone

python manage.py runserver

load in browser http://localhost:8000



Step 02 completed , we now should do the step 03
http://djangobook.com/en/2.0/chapter03/

Chapter 3 is quite easy to read mainly hello world application here is the screenshot
after finising it (no modifications needed or related to firebird)



Chapter 04 is only related to templates so no modifications needed related to firebird.

So we reached chapter 05 the db and the The MTV Development Pattern (Beavis and Butthead pattern maybe )
http://djangobook.com/en/2.0/chapter05/

In a way i like the Dumb pattern ViewController
Only the View and the Controller and The Model is in database anyway (triggers/rules/procedures and business logic)

I have created an empty database in /var/lib/firebird/2.5/data/firedjango.fdb
with flamerobin

Ok so the the shell worked with my firebird db config in settings.py

$python manage.py shell
>>> from django.db import connection
>>> cursor = connection.cursor()

So the next thing was to create the models and generate the db

$ python manage.py validate
$ python manage.py sqlall books

and here is the output

After that sync worked
$ python manage.py syncdb
import md5
Creating table books_publisher
Creating table books_book
Creating table books_author
Installing index for books.Book model

$ python manage.py shell
(InteractiveConsole)
>>> from books.models import Publisher
>>> p1 = Publisher(name='Apress', address='2855 Telegraph Avenue',
... city='Berkeley', state_province='CA', country='U.S.A.',
... website='http://www.apress.com/')
>>> p1.save()
>>> p2 = Publisher(name="O'Reilly", address='10 Fawcett St.',
... city='Cambridge', state_province='MA', country='U.S.A.',
... website='http://www.oreilly.com/')
>>> p2.save()
>>> publisher_list = Publisher.objects.all()
>>> publisher_list
[, ]



after i have added the _unicode method

$ python manage.py shell

>>> from books.models import Publisher
>>> publisher_list = Publisher.objects.all()
>>> publisher_list
[<Publisher: Apress>, <Publisher: O'Reilly>]