I recently found that you can pass a list or tuple to both django.template.loader.render_to_string and django.shortcuts.render_to_response. These functions iterate over the list of templates and render the first template that exists. The magic lies with the django.template.loader.get_template and select_template functions which take a single template name or list of templates respectively.
This is a great functionality [...]
How do you get the model class object from a string containing model name?
This came up multiple times during SeenReport development. While recording views, saving votes and adding comment on an object, I had to get the model class using the model name. The scenario would be,
The view receives the model name and object id
Fetch [...]
As I mentioned earlier, django provides a convenient and highly de-coupled way to manipulate URLs. At the heart of this functionality is django.core.urlresolver.reverse. This function however generates relative URLs e.g. /album/my-first-album/
At See’n’Report, we wanted every user to have a sub-domain so, hitting http://username.seenreport.com takes you to the user profile. But this created a small problem; all [...]
Django provides models.FileField & models.ImageField to save uploaded files & images respectively. Both these fields take a parameters ‘upload_to’ which defines the path where the uploaded file will be saved (complete path is settings.MEDIA_ROOT + upload_to). You can play some neat tricks with this little feature.
Creating the date based folders at run time
You can use the [...]
Writing is not just a mode of communication, it is a medium to refine, share grow ideas. It forces you to organize your thoughts in a meaningful way. When you write your thoughts, you can clearly see if you make sense or not. People fail to grasp that writing is a skill and requires conscious [...]
I used Firefox in 2005 for the first time and immediately fell in love with it. Downloading Firefox is probably the only thing for which I use Internet Explorer now.
A great thing about Firefox is the available plugins. Over the past 4 years, I have installed & uninstalled many add-ons. Following are the 10 add-ons [...]
Response time of a web site is a critical component of user experience. Here are some practical steps to reduce your response time.
It is recommended that you install Firebug and YSlow before you proceed. YSlow provides you with a wealth of statistics about your page (server requests, external file size, response time, images size etc.)
1- Place [...]
If you are migrating to django 1.0, youll have to update your models.py for django newforms-admin
Before
from django.db import models
class MyModel(models.Model):
"""
field definitions
"""
class Admin
[...]