Using Django with a small team

Up until recently I have been working on Django based projects all by myself. In last few weeks I have been working with with a designer who does the templates and graphics while I handle the modeling, python and other admin stuff (svn, mysql).

At first things were a little tricky because of our different environments and our constantly having to change the settings.py and urls.py according to each individual machine. You can imagine that this didn't work well with svn because changing the DATABASE_USER param was not really a change that needed to be commited, yet a change to the INSTALLED_APPS does need to be commited.

Because the urls and settings files are just python files I can create individual files for each machine that imports all the settings from the 'global' file. For example if Tom has his database names 'coolProject' and Harry has his database set as Cool_Project then we create 2 new files:

settingsTom.py

from settings import *
DATABASE_NAME = 'coolProject'
DATABASE_USER = 'Tom'
DATABASE_PASSWORD = 'password'
DATABASE_HOST = ''
DATABASE_PORT = ''
ROOT_URLCONF = 'myproject.urlsTom'
TEMPLATE_DIRS = (
    # Put strings here, like "/home/html/django_templates".
    "/Users/tom/python/myproject/templates",
)

MEDIA_ROOT = '/Users/tom/python/myproject/site_media/'
MEDIA_URL = 'http://127.0.0.1:8000/site_media/'

settingsHarry.py

from settings import *

DATABASE_NAME = 'cool_project'
DATABASE_USER = 'Harry'
DATABASE_PASSWORD = 'password'
DATABASE_HOST = ''
DATABASE_PORT = ''
ROOT_URLCONF = 'myproject.urlsHarry'

TEMPLATE_DIRS = (
    # Put strings here, like "/home/html/django_templates".
    "/Users/harry/workspace/myproject/templates",
)

MEDIA_ROOT = '/Users/harry/python/myproject/site_media/'
MEDIA_URL = 'http://192.168.0.1:8000/site_media/'

Now Tom will use DJANGO_SETTINGS_MODULE=myproject.settingsTom.py and Harry will use DJANGO_SETTINGS_MODULE=myproject.seetingsHarry.py.

Notice that each user has there own ROOT_URLCONF. This allows each user to configure how they use Django to server static files. An example of urlsTom.py would be something like this.

urlsTom.py

from django.conf.urls.defaults import *
from impactsports.urls import *

oldpatterns = urlpatterns
urlpatterns = patterns('',
    (r'^impact_media/(?P.*)$', 'django.views.static.serve', 
    {'document_root': '/home/tom/python/myproject/site_media', 'show_indexes': True}), 
)
for pattern in oldpatterns:
    urlpatterns.append(pattern)

This has saved lots of time now that I don't have to tweak the settings.py and urls.py file to work with my environment every time there is a change in one of them.





Powered by Django.