Skip to content

Commit 4bd6f66

Browse files
committed
first commit
0 parents  commit 4bd6f66

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

70 files changed

+18005
-0
lines changed

db.sqlite3

140 KB
Binary file not shown.

db.sqlite3.db

Whitespace-only changes.

main

Whitespace-only changes.

main.db

Whitespace-only changes.

manage.py

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#!/usr/bin/env python
2+
import os
3+
import sys
4+
5+
if __name__ == "__main__":
6+
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "mysite.settings")
7+
try:
8+
from django.core.management import execute_from_command_line
9+
except ImportError as exc:
10+
raise ImportError(
11+
"Couldn't import Django. Are you sure it's installed and "
12+
"available on your PYTHONPATH environment variable? Did you "
13+
"forget to activate a virtual environment?"
14+
) from exc
15+
execute_from_command_line(sys.argv)

mysite/__init__.py

Whitespace-only changes.
120 Bytes
Binary file not shown.
2.24 KB
Binary file not shown.
986 Bytes
Binary file not shown.
521 Bytes
Binary file not shown.

mysite/settings.py

+122
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
"""
2+
Django settings for mysite project.
3+
4+
Generated by 'django-admin startproject' using Django 2.0.5.
5+
6+
For more information on this file, see
7+
https://docs.djangoproject.com/en/2.0/topics/settings/
8+
9+
For the full list of settings and their values, see
10+
https://docs.djangoproject.com/en/2.0/ref/settings/
11+
"""
12+
13+
import os
14+
15+
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
16+
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
17+
18+
19+
# Quick-start development settings - unsuitable for production
20+
# See https://docs.djangoproject.com/en/2.0/howto/deployment/checklist/
21+
22+
# SECURITY WARNING: keep the secret key used in production secret!
23+
SECRET_KEY = '+8&zjc$293bh#mjrsk@o))c0=#6n4rz66q*swp8(@_ju$so=+a'
24+
25+
# SECURITY WARNING: don't run with debug turned on in production!
26+
DEBUG = True
27+
28+
ALLOWED_HOSTS = []
29+
30+
31+
# Application definition
32+
33+
INSTALLED_APPS = [
34+
'products.apps.ProductsConfig',
35+
'polls.apps.PollsConfig',
36+
'django.contrib.admin',
37+
'django.contrib.auth',
38+
'django.contrib.contenttypes',
39+
'django.contrib.sessions',
40+
'django.contrib.messages',
41+
'django.contrib.staticfiles',
42+
]
43+
44+
MIDDLEWARE = [
45+
'django.middleware.security.SecurityMiddleware',
46+
'django.contrib.sessions.middleware.SessionMiddleware',
47+
'django.middleware.common.CommonMiddleware',
48+
'django.middleware.csrf.CsrfViewMiddleware',
49+
'django.contrib.auth.middleware.AuthenticationMiddleware',
50+
'django.contrib.messages.middleware.MessageMiddleware',
51+
'django.middleware.clickjacking.XFrameOptionsMiddleware',
52+
]
53+
54+
ROOT_URLCONF = 'mysite.urls'
55+
56+
TEMPLATES = [
57+
{
58+
'BACKEND': 'django.template.backends.django.DjangoTemplates',
59+
'DIRS': [],
60+
'APP_DIRS': True,
61+
'OPTIONS': {
62+
'context_processors': [
63+
'django.template.context_processors.debug',
64+
'django.template.context_processors.request',
65+
'django.contrib.auth.context_processors.auth',
66+
'django.contrib.messages.context_processors.messages',
67+
],
68+
},
69+
},
70+
]
71+
72+
WSGI_APPLICATION = 'mysite.wsgi.application'
73+
74+
75+
# Database
76+
# https://docs.djangoproject.com/en/2.0/ref/settings/#databases
77+
78+
DATABASES = {
79+
'default': {
80+
'ENGINE': 'django.db.backends.sqlite3',
81+
'NAME': os.path.join(BASE_DIR, 'productdb'),
82+
}
83+
}
84+
85+
86+
# Password validation
87+
# https://docs.djangoproject.com/en/2.0/ref/settings/#auth-password-validators
88+
89+
AUTH_PASSWORD_VALIDATORS = [
90+
{
91+
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
92+
},
93+
{
94+
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
95+
},
96+
{
97+
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
98+
},
99+
{
100+
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
101+
},
102+
]
103+
104+
105+
# Internationalization
106+
# https://docs.djangoproject.com/en/2.0/topics/i18n/
107+
108+
LANGUAGE_CODE = 'en-us'
109+
110+
TIME_ZONE = 'Asia/Kolkata'
111+
112+
USE_I18N = True
113+
114+
USE_L10N = True
115+
116+
USE_TZ = True
117+
118+
119+
# Static files (CSS, JavaScript, Images)
120+
# https://docs.djangoproject.com/en/2.0/howto/static-files/
121+
122+
STATIC_URL = '/static/'

mysite/urls.py

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
"""mysite URL Configuration
2+
3+
The `urlpatterns` list routes URLs to views. For more information please see:
4+
https://docs.djangoproject.com/en/2.0/topics/http/urls/
5+
Examples:
6+
Function views
7+
1. Add an import: from my_app import views
8+
2. Add a URL to urlpatterns: path('', views.home, name='home')
9+
Class-based views
10+
1. Add an import: from other_app.views import Home
11+
2. Add a URL to urlpatterns: path('', Home.as_view(), name='home')
12+
Including another URLconf
13+
1. Import the include() function: from django.urls import include, path
14+
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
15+
"""
16+
from django.contrib import admin
17+
from django.urls import include, path
18+
19+
urlpatterns = [
20+
path('polls/', include('polls.urls')),
21+
path('products/', include('products.urls')),
22+
path('admin/', admin.site.urls),
23+
]

mysite/wsgi.py

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
"""
2+
WSGI config for mysite project.
3+
4+
It exposes the WSGI callable as a module-level variable named ``application``.
5+
6+
For more information on this file, see
7+
https://docs.djangoproject.com/en/2.0/howto/deployment/wsgi/
8+
"""
9+
10+
import os
11+
12+
from django.core.wsgi import get_wsgi_application
13+
14+
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "mysite.settings")
15+
16+
application = get_wsgi_application()

polls/__init__.py

Whitespace-only changes.
119 Bytes
Binary file not shown.
493 Bytes
Binary file not shown.

polls/__pycache__/apps.cpython-36.pyc

333 Bytes
Binary file not shown.
1.2 KB
Binary file not shown.

polls/__pycache__/urls.cpython-36.pyc

454 Bytes
Binary file not shown.
1.67 KB
Binary file not shown.

polls/admin.py

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
from django.contrib import admin
2+
3+
# Register your models here.
4+
5+
from .models import Question
6+
7+
8+
class QuestionAdmin(admin.ModelAdmin):
9+
fieldsets = [
10+
(None, {'fields': ['question_text']}),
11+
('Date info', {'fields': ['pub_date']}),
12+
]
13+
14+
15+
admin.site.register(Question, QuestionAdmin)

polls/apps.py

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
from django.apps import AppConfig
2+
3+
4+
class PollsConfig(AppConfig):
5+
name = 'polls'

polls/migrations/0001_initial.py

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# Generated by Django 2.0.5 on 2018-05-18 08:35
2+
3+
from django.db import migrations, models
4+
import django.db.models.deletion
5+
6+
7+
class Migration(migrations.Migration):
8+
9+
initial = True
10+
11+
dependencies = [
12+
]
13+
14+
operations = [
15+
migrations.CreateModel(
16+
name='Choice',
17+
fields=[
18+
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
19+
('choice_text', models.CharField(max_length=200)),
20+
('votes', models.IntegerField(default=0)),
21+
],
22+
),
23+
migrations.CreateModel(
24+
name='Question',
25+
fields=[
26+
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
27+
('question_text', models.CharField(max_length=200)),
28+
('pub_date', models.DateTimeField(verbose_name='date published')),
29+
],
30+
),
31+
migrations.AddField(
32+
model_name='choice',
33+
name='question',
34+
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='polls.Question'),
35+
),
36+
]

polls/migrations/__init__.py

Whitespace-only changes.
Binary file not shown.
Binary file not shown.

polls/models.py

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import datetime
2+
3+
from django.db import models
4+
from django.utils import timezone
5+
# Create your models here.
6+
7+
8+
class Question(models.Model):
9+
question_text = models.CharField(max_length=200)
10+
pub_date = models.DateTimeField('date published')
11+
12+
def __str__(self):
13+
return self.question_text
14+
15+
def was_publish_recently(self):
16+
return self.pub_date >= timezone.now() - datetime.timedelta(days=1)
17+
18+
19+
class Choice(models.Model):
20+
question = models.ForeignKey(Question, on_delete=models.CASCADE)
21+
choice_text = models.CharField(max_length=200)
22+
votes = models.IntegerField(default=0)
23+
24+
def __str__(self):
25+
return self.choice_text

polls/templates/polls/detail.html

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<h1>{{ question.question_text }}</h1>
2+
3+
{% if error_message %}
4+
<p>
5+
<strong>{{ error_message }}</strong>
6+
</p>{% endif %}
7+
8+
<form action="{% url 'polls:vote' question.id %}" method="post">
9+
{% csrf_token %} {% for choice in question.choice_set.all %}
10+
<input type="radio" name="choice" id="choice{{ forloop.counter }}" value="{{ choice.id }}" />
11+
<label for="choice{{ forloop.counter }}">{{ choice.choice_text }}</label>
12+
<br /> {% endfor %}
13+
<input type="submit" value="Vote" />
14+
</form>

polls/templates/polls/index.html

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{% if latest_question_list %}
2+
<ul>
3+
{% for question in latest_question_list %}
4+
<li>
5+
<a href="{% url 'polls:detail' question.id %}">{{ question.question_text }}</a>
6+
</li>
7+
{% endfor %}
8+
</ul>
9+
{% else %}
10+
<p>No polls are available.</p>
11+
{% endif %}

polls/templates/polls/results.html

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<h1>{{ question.question_text }}</h1>
2+
3+
<ul>
4+
{% for choice in question.choice_set.all %}
5+
<li>{{ choice.choice_text }} -- {{ choice.votes }} vote{{ choice.votes|pluralize }}</li>
6+
{% endfor %}
7+
</ul>
8+
9+
<a href="{% url 'polls:detail' question.id %}">Vote again?</a>

polls/tests.py

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from django.test import TestCase
2+
3+
# Create your tests here.

polls/urls.py

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
from django.urls import path
2+
from . import views
3+
4+
app_name = 'polls'
5+
urlpatterns = [
6+
path('', views.IndexView.as_view(), name='index'),
7+
8+
path('<int:pk>/', views.DetailView.as_view(), name="detail"),
9+
path('<int:pk>/results/', views.ResultsView.as_view(), name="results"),
10+
path('<int:question_id>/vote/', views.vote, name="vote"),
11+
12+
]

polls/views.py

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
from django.shortcuts import get_object_or_404, render
2+
from django.http import HttpResponse, Http404, HttpResponseRedirect
3+
from django.urls import reverse
4+
from django.views import generic
5+
from .models import Question, Choice
6+
# Create your views here.
7+
8+
9+
class IndexView(generic.ListView):
10+
template_name = 'polls/index.html'
11+
context_object_name = 'latest_question_list'
12+
13+
def get_queryset(self):
14+
return Question.objects.order_by('-pub_date')[:5]
15+
16+
17+
class DetailView(generic.DetailView):
18+
model = Question
19+
template_name = 'polls/detail.html'
20+
21+
22+
class ResultsView(generic.DetailView):
23+
model = Question
24+
template_name = 'polls/results.html'
25+
26+
27+
def vote(request, question_id):
28+
question = get_object_or_404(Question, pk=question_id)
29+
try:
30+
selected_choice = question.choice_set.get(pk=request.POST['choice'])
31+
except (KeyError, Choice.DoesNotExist):
32+
return render(request, 'polls/detail.html', {'question': question, 'error_message': 'you didnt select a choice'})
33+
else:
34+
selected_choice.votes += 1
35+
selected_choice.save()
36+
return HttpResponseRedirect(reverse('polls:results', args=(question.id,)))

productdb

148 KB
Binary file not shown.

products/__init__.py

Whitespace-only changes.
122 Bytes
Binary file not shown.
237 Bytes
Binary file not shown.
342 Bytes
Binary file not shown.
727 Bytes
Binary file not shown.
588 Bytes
Binary file not shown.
666 Bytes
Binary file not shown.
2.32 KB
Binary file not shown.

products/admin.py

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
from django.contrib import admin
2+
3+
# Register your models here.
4+
from .models import Products
5+
6+
admin.site.register(Products)

products/apps.py

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
from django.apps import AppConfig
2+
3+
4+
class ProductsConfig(AppConfig):
5+
name = 'products'

products/forms.py

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
from django import forms
2+
from products.models import Products
3+
4+
5+
class ProductsForm(forms.Form):
6+
product_name = forms.CharField(required=False)
7+
product_type = forms.CharField(required=False)
8+
quantity = forms.IntegerField(required=False)
9+
10+
def clean_name(self):
11+
name = self.cleaned_data.get("proname")
12+
if name == "Hello":
13+
raise forms.ValidationError("Not a valid name")
14+
return name

0 commit comments

Comments
 (0)