django_try again

This commit is contained in:
bendtherules
2014-02-27 05:30:16 +05:30
parent 34c64f7ff1
commit c6bd1dd5c4
26 changed files with 185 additions and 304 deletions
Binary file not shown.
@@ -0,0 +1,83 @@
"""
Django settings for firstsite project.
For more information on this file, see
https://docs.djangoproject.com/en/1.6/topics/settings/
For the full list of settings and their values, see
https://docs.djangoproject.com/en/1.6/ref/settings/
"""
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
import os
BASE_DIR = os.path.dirname(os.path.dirname(__file__))
# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/1.6/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = '3%%09s1(0@v9vz@kjc)^j)+a6d1i6i-0q^%gknd*&lxh4nkgtk'
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
TEMPLATE_DEBUG = True
ALLOWED_HOSTS = []
# Application definition
INSTALLED_APPS = (
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
"polls"
)
MIDDLEWARE_CLASSES = (
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
)
ROOT_URLCONF = 'firstsite.urls'
WSGI_APPLICATION = 'firstsite.wsgi.application'
# Database
# https://docs.djangoproject.com/en/1.6/ref/settings/#databases
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
}
}
# Internationalization
# https://docs.djangoproject.com/en/1.6/topics/i18n/
LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'Asia/Kolkata'
USE_I18N = True
USE_L10N = True
USE_TZ = True
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.6/howto/static-files/
STATIC_URL = '/static/'
+13
View File
@@ -0,0 +1,13 @@
from django.conf.urls import patterns, include, url
from django.contrib import admin
admin.autodiscover()
urlpatterns = patterns('',
# Examples:
# url(r'^$', 'firstsite.views.home', name='home'),
# url(r'^blog/', include('blog.urls')),
url(r'^admin/', include(admin.site.urls)),
url(r"^polls/",include("polls.urls"))
)
+14
View File
@@ -0,0 +1,14 @@
"""
WSGI config for firstsite project.
It exposes the WSGI callable as a module-level variable named ``application``.
For more information on this file, see
https://docs.djangoproject.com/en/1.6/howto/deployment/wsgi/
"""
import os
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "firstsite.settings")
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()
+10
View File
@@ -0,0 +1,10 @@
#!/usr/bin/env python
import os
import sys
if __name__ == "__main__":
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "firstsite.settings")
from django.core.management import execute_from_command_line
execute_from_command_line(sys.argv)
+6
View File
@@ -0,0 +1,6 @@
from django.contrib import admin
from polls.models import Poll, Choice
# Register your models here.
admin.site.register(Poll)
admin.site.register(Choice)
+20
View File
@@ -0,0 +1,20 @@
from django.db import models
import datetime
from django.utils import timezone
# Create your models here.
class Poll(models.Model):
question=models.CharField(max_length=200)
pub_date=models.DateTimeField("date published")
def __unicode__(self):
return self.question
def time_passed(self):
return timezone.now()-self.pub_date
class Choice(models.Model):
poll=models.ForeignKey(Poll)
choice_text=models.CharField(max_length=200)
votes=models.IntegerField(default=0)
def __unicode__(self):
return self.choice_text
@@ -0,0 +1,22 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Polls</title>
</head>
<body>
{% if latest_poll_list %}
<ul>
{% for poll in latest_poll_list %}
<li>
<a href="/polls/{{poll.id}}">{{poll.question}}</a>
</li>
{% endfor %}
</ul>
{% else %}
<p>
No polls found
</p>
{% endif %}
</body>
</html>
+3
View File
@@ -0,0 +1,3 @@
from django.test import TestCase
# Create your tests here.
+10
View File
@@ -0,0 +1,10 @@
from django.conf.urls import patterns, url
from polls import views
urlpatterns=patterns("",
url(r"^$",views.index,name="index"),
url(r"^(?P<poll_id>\d+)/$",views.detail,name="detail"),
url(r"^(?P<poll_id>\d+)/results/$",views.results,name="results"),
url(r"^(?P<poll_id>\d+)/vote/$",views.vote,name="vote"),
)
+30
View File
@@ -0,0 +1,30 @@
from django.shortcuts import render
from django.http import HttpResponse
from polls.models import Poll, Choice
from django.template import RequestContext, loader
# Create your views here.
def index_old(request):
latest_poll_list=Poll.objects.order_by("-pub_date")[:5]
template=loader.get_template(r"polls/index.html")
context=RequestContext(request,{
"latest_poll_list":latest_poll_list.reverse(), # reversed additionally
})
return HttpResponse(template.render(context))
## output=r"<br>".join([p.question for p in latest_poll_list])
## return HttpResponse(output)
def index(request):
latest_poll_list=Poll.objects.order_by("-pub_date")[:5]
context={"latest_poll_list":latest_poll_list}
return render(request,r"polls/index.html",context)
def detail(request,poll_id):
return HttpResponse("Here are the details of poll %s" % poll_id)
def vote(request,poll_id):
return HttpResponse("You voted for poll %s" % poll_id)
def results(request,poll_id):
return HttpResponse("Here are the results of Poll %s" % poll_id)