Monday, January 10, 2011

Practical Django projects - Continuing with the CMS

- The admin application's templates can be changed. By default the admin application looks for a template first in the added application directory itself (flatpages application in this case).If not available, then it looks at the directories of the admin application.

- Created a new app for search. This will need an app created using 'manage.py search' since its a separate app and needs a model.

- Strangely, you can invoke any python code as a view function on your computer, even one that's not in INSTALLED_APPS as long as it can be found by django. If that python code needs a model though, it has to go in INSTALLED_APPS.

- Filter method on model objects has argument string built as "__=" and returns list of model objects.

- Template object is created using the path to the html file as parameter. The template is rendered by using a Context object as parameter which is a dictionary with variable name as dict key and variable value as dict value. These variables can be accessed in the html template file using Django template syntax.

- django.shortcuts.render_to_response is a useful facade to just take html file and a dictionary of parameters to do all the above.

- You can change the way the editing for a model object is rendered in the admin app. This has a clear api where you unregister the existing admin class for model and then subclass the admin class with a customized model. Once this is done, you re-register the new admin class for the same model.

- django.http.HttpResponseRedirect is a useful helper method if you want to redirect the results of a model object search to a specific url.