Roshan Book

My Tech Notebook

Revision before creating an app


How Django process your request

 

Starting your project – django-admin.py startproject mysite

Running sever – python manage.py runserver 8080

Sync Db – python manage.py syncdb

Set up database type in settings.py

Starting an app– python manage.py startapp polls

Add app to settings.py under “installed app”

A Sample model to revise :

from django.db import models

class Poll(models.Model):
    question = models.CharField(max_length=200)
    pub_date = models.DateTimeField('date published')
     def __unicode__(self):
        return self.question

class Choice(models.Model):
    poll = models.ForeignKey(Poll)
    choice = models.CharField(max_length=200)
    votes = models.IntegerField()
    def __unicode__(self):
        return self.question
Sync db - python manage.py syncdb
See the sql -python manage.py sql polls
Getting into your app shell : python manage.py shell
InSide shell:
from polls.models import Poll, Choice
For more command visit here
Activating the admin site

Activate the admin site

The Django admin site is not activated by default – it’s an opt-in thing. To activate the admin site for your installation, do these three things:

  • Add "django.contrib.admin" to your INSTALLED_APPS setting.
  • Run python manage.py syncdb. Since you have added a new application toINSTALLED_APPS, the database tables need to be updated.
  • Edit your mysite/urls.py file and uncomment the lines that reference the admin – there are three lines in total to uncomment. This file is a URLconf; we’ll dig into URLconfs in the next tutorial. For now, all you need to know is that it maps URL roots to applications. In the end, you should have a urls.py file that looks like this:
    from django.conf.urls.defaults import patterns, include, url
    
    # Uncomment the next two lines to enable the admin:
    from django.contrib import admin
    admin.autodiscover()
    
    urlpatterns = patterns('',
        # Examples:
        # url(r'^$', 'mysite.views.home', name='home'),
        # url(r'^mysite/', include('mysite.foo.urls')),
    
        # Uncomment the admin/doc line below to enable admin documentation:
        # url(r'^admin/doc/', include('django.contrib.admindocs.urls')),
    
        # Uncomment the next line to enable the admin:
        url(r'^admin/', include(admin.site.urls)),
    )

    (The bold lines are the ones that needed to be uncommented.)







Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: