Code


Version 1 (modified by anonymous, 8 years ago) (diff)

--

1. Create a Django Project

django-admin.py startproject AcmeIntranet
cd AcmeIntranet
edit settings.py
  • edit your database settings
  • set path to media dir

media contains public files such as css and js files this path might be: /home/joe/AcmeIntranet/media

  • set path to template dir

templates contains django html templates your applications will likely have their own template dirs. Remember to add those as you create them

2. Create invoices application.

Edit urls.py to point to the app you will create (r'^invoices/', include('AcmeIntranet.invoices.urls'))

Create the invoices app

python manage.py startapp invoices
cd invoices

edit models.py

class Invoice(models.Model):
  dollar_ammount = models.FloatField('Cost (in dollars)', max_digits=10, decimal_places=2)

Create and edit urls.py

from django.conf.urls.defaults import *
from AcmeIntranet.invoices.models import Invoice

info_dict = {
  'queryset': Invoice.objects.all()
}

urlpatterns = patterns('',
    (r'^$', 'django.views.generic.list_detail.object_list', info_dict),
    (r'^new/$', 'django.views.generic.create_update.???', { 'model': Invoice } ),
    (r'^(?P<object_id>\d+)/$', 'django.views.generic.list_detail.object_detail', info_dict),
)