Thursday, July 31, 2008

Django 0.96 and 1.0 alpha

The web framework for perfectionists with deadlines.
Django makes it easier to build better Web apps more quickly and with less code.

These notes refer to Django version 0.96 and 1.0 alpha:

GREAT so far:
* model-db-tables creation
* template inheritance
* great documentation
* fixtures

PROBLEMS so far:
* creating CRUD forms
* upgrading models sometimes requires going to the rdbms admin software to alter or drop the table
* console commands to administer, validate, reset, etc

* generic views:
* edit
* (r'^incomes/list/$', 'imbr.incomes.views.income_list'),
* edit
* return an object_list()
* edit
* create a ModelForm for your models

* django generic wrapper howto:
* django.views.generic.list_detail.object_list has "object_list" as the name of the variable for use on your templates. This is overridable.
* django.views.generic.list_detail.object_detail has "object" as the name of the variable for use on your templates. This is overridable.

* use babel,, a Python library for I18N and L10N - use BabelDjango for your django projects
* to round-off decimals at django templates use the floatformat filter (ie 34.23234 --> {{ value|floatformat:3 }} --> 34.232)

* to use alternating rows, use CYCLE, make sure not to put spaces between the values, only commas.

* iif() equivalent == (c and (a,) or (b,))[0] from

* in postgresql, an error in adding data will occur if database is prepopulated by data from fixtures. Use "python sqlsequencereset catalog | psql -U postgres -d lms" after loading your fixtures. Issue Ticket is

* fixtures as json are much easier to maintain: add, edit, and remove records
* to save data as fixtures: python dumpdata --format=json --indent=4 catalog > catalog/initial_data.json
* to load data as fixtures: python loaddata catalog/initial_data.json
* use fixtures to add initial data to your database
* use unittest as unit tests for your models


2008-05-28 (chapter 7):
* redirect after POST to prevent saving duplicate record

2008-05-26 (chapter 7):
* escape variables in your templates to prevent XSS

2008-05-26 (chapter 5):
* for "python dbshell" to work under sqlite3 db, download the sqlite3.exe executable from and put it somewhere in your path
* put __str__() method to all model classes for a string representation of the class
* use PIL (python imaging library) for ImageFields in your model at
* django requires single column primary key
* django uses the MTV (model-template-view) framework. In MVC framework, Model = django.model, View = django.views and django.templates, Controller = django.URLconfs

2008-05-25: (chapter 4)
* Template inheritance can be nested to whatever level
* Templates are the Views in MVC model
* Templates have their own language but just enough for "presentation" level, if you want to add logic, use a View

Labels: , ,


Post a Comment

<< Home