├── LICENSE ├── README.md ├── SUTT ├── __init__.py ├── __pycache__ │ ├── __init__.cpython-39.pyc │ ├── settings.cpython-39.pyc │ ├── urls.cpython-39.pyc │ └── wsgi.cpython-39.pyc ├── asgi.py ├── settings.py ├── urls.py └── wsgi.py ├── landingpage ├── __init__.py ├── __pycache__ │ ├── __init__.cpython-39.pyc │ ├── urls.cpython-39.pyc │ └── views.cpython-39.pyc ├── admin.py ├── apps.py ├── migrations │ └── __init__.py ├── models.py ├── tests.py ├── urls.py └── views.py ├── manage.py └── polls ├── __init__.py ├── __pycache__ ├── __init__.cpython-39.pyc ├── admin.cpython-39.pyc ├── apps.cpython-39.pyc ├── models.cpython-39.pyc ├── urls.cpython-39.pyc └── views.cpython-39.pyc ├── admin.py ├── apps.py ├── migrations ├── 0001_initial.py ├── __init__.py └── __pycache__ │ ├── 0001_initial.cpython-39.pyc │ └── __init__.cpython-39.pyc ├── models.py ├── templates ├── landingpage │ └── home.html └── polls │ ├── detail.html │ ├── home.html │ └── results.html ├── tests.py ├── urls.py └── views.py /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2022 Nikhil Handa 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Polls App 2 | 3 | The project uses Django Framework in Python and MySQL as database. 4 | 5 | A) The Project Contains 2 Apps : 6 | 1. The Main Polls App. 7 | 2. A Landing Page for the user on launching the server. 8 | 9 | B) The Following views have been created in the Polls App: 10 | 1. Home Page (named home) 11 | 2. Detail Page (A page containing detailed description of Every Question) 12 | 3. Results Page (Live Detail of which options of particular question has how many votes) 13 | 4. Vote (To record the Selected Choice) 14 | 15 | C) The Following Classes are created for Polls App : 16 | 1. Question (Contains the Question Text [255 charecters] and Date Published) 17 | 2. Choice (Contains Question ID [Foreign Key Reference], Text [255 chars], Votes [No. of Votes for the particular choice]) 18 | 19 | D) Through Admin.py, Django Default UI has been enabled and can be used to Feed New Questions and Choices 20 | 21 | E) Templates have been written in HTML for Landing Page, Polls HomePage, Detail Page, and Results Page 22 | -------------------------------------------------------------------------------- /SUTT/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/0xp3p3x0/Django-backend/10c2e66df9248ad5b0d7f281f158d5bebbd9acb3/SUTT/__init__.py -------------------------------------------------------------------------------- /SUTT/__pycache__/__init__.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/0xp3p3x0/Django-backend/10c2e66df9248ad5b0d7f281f158d5bebbd9acb3/SUTT/__pycache__/__init__.cpython-39.pyc -------------------------------------------------------------------------------- /SUTT/__pycache__/settings.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/0xp3p3x0/Django-backend/10c2e66df9248ad5b0d7f281f158d5bebbd9acb3/SUTT/__pycache__/settings.cpython-39.pyc -------------------------------------------------------------------------------- /SUTT/__pycache__/urls.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/0xp3p3x0/Django-backend/10c2e66df9248ad5b0d7f281f158d5bebbd9acb3/SUTT/__pycache__/urls.cpython-39.pyc -------------------------------------------------------------------------------- /SUTT/__pycache__/wsgi.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/0xp3p3x0/Django-backend/10c2e66df9248ad5b0d7f281f158d5bebbd9acb3/SUTT/__pycache__/wsgi.cpython-39.pyc -------------------------------------------------------------------------------- /SUTT/asgi.py: -------------------------------------------------------------------------------- 1 | """ 2 | ASGI config for SUTT project. 3 | 4 | It exposes the ASGI callable as a module-level variable named ``application``. 5 | 6 | For more information on this file, see 7 | https://docs.djangoproject.com/en/4.1/howto/deployment/asgi/ 8 | """ 9 | 10 | import os 11 | 12 | from django.core.asgi import get_asgi_application 13 | 14 | os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'SUTT.settings') 15 | 16 | application = get_asgi_application() 17 | -------------------------------------------------------------------------------- /SUTT/settings.py: -------------------------------------------------------------------------------- 1 | """ 2 | Django settings for SUTT project. 3 | 4 | Generated by 'django-admin startproject' using Django 4.1.3. 5 | 6 | For more information on this file, see 7 | https://docs.djangoproject.com/en/4.1/topics/settings/ 8 | 9 | For the full list of settings and their values, see 10 | https://docs.djangoproject.com/en/4.1/ref/settings/ 11 | """ 12 | 13 | from pathlib import Path 14 | 15 | # Build paths inside the project like this: BASE_DIR / 'subdir'. 16 | BASE_DIR = Path(__file__).resolve().parent.parent 17 | 18 | 19 | # Quick-start development settings - unsuitable for production 20 | # See https://docs.djangoproject.com/en/4.1/howto/deployment/checklist/ 21 | 22 | # SECURITY WARNING: keep the secret key used in production secret! 23 | SECRET_KEY = 'django-insecure-4mg7h@!5i)j7%!98dv*f)#28w5pjpzu5bnsz6wssp#d$gcviv6' 24 | 25 | # SECURITY WARNING: don't run with debug turned on in production! 26 | DEBUG = True 27 | 28 | ALLOWED_HOSTS = [] 29 | 30 | # Application definition 31 | 32 | INSTALLED_APPS = [ 33 | 'polls.apps.PollsConfig', 34 | 'django.contrib.admin', 35 | 'django.contrib.auth', 36 | 'django.contrib.contenttypes', 37 | 'django.contrib.sessions', 38 | 'django.contrib.messages', 39 | 'django.contrib.staticfiles', 40 | ] 41 | 42 | MIDDLEWARE = [ 43 | 'django.middleware.security.SecurityMiddleware', 44 | 'django.contrib.sessions.middleware.SessionMiddleware', 45 | 'django.middleware.common.CommonMiddleware', 46 | 'django.middleware.csrf.CsrfViewMiddleware', 47 | 'django.contrib.auth.middleware.AuthenticationMiddleware', 48 | 'django.contrib.messages.middleware.MessageMiddleware', 49 | 'django.middleware.clickjacking.XFrameOptionsMiddleware', 50 | ] 51 | 52 | ROOT_URLCONF = 'SUTT.urls' 53 | 54 | TEMPLATES = [ 55 | { 56 | 'BACKEND': 'django.template.backends.django.DjangoTemplates', 57 | 'DIRS': [], 58 | 'APP_DIRS': True, 59 | 'OPTIONS': { 60 | 'context_processors': [ 61 | 'django.template.context_processors.debug', 62 | 'django.template.context_processors.request', 63 | 'django.contrib.auth.context_processors.auth', 64 | 'django.contrib.messages.context_processors.messages', 65 | ], 66 | }, 67 | }, 68 | ] 69 | 70 | WSGI_APPLICATION = 'SUTT.wsgi.application' 71 | 72 | 73 | # Database 74 | # https://docs.djangoproject.com/en/4.1/ref/settings/#databases 75 | 76 | DATABASES = { 77 | 'default': { 78 | 'ENGINE': 'django.db.backends.mysql', 79 | 'HOST':'localhost', 80 | 'USER':'root', 81 | 'PASSWORD':'Nikhil@123', 82 | 'NAME':'Polls' 83 | } 84 | } 85 | 86 | 87 | # Password validation 88 | # https://docs.djangoproject.com/en/4.1/ref/settings/#auth-password-validators 89 | 90 | AUTH_PASSWORD_VALIDATORS = [ 91 | { 92 | 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator', 93 | }, 94 | { 95 | 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator', 96 | }, 97 | { 98 | 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator', 99 | }, 100 | { 101 | 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator', 102 | }, 103 | ] 104 | 105 | 106 | # Internationalization 107 | # https://docs.djangoproject.com/en/4.1/topics/i18n/ 108 | 109 | LANGUAGE_CODE = 'en-us' 110 | 111 | TIME_ZONE = 'UTC' 112 | 113 | USE_I18N = True 114 | 115 | USE_TZ = True 116 | 117 | 118 | # Static files (CSS, JavaScript, Images) 119 | # https://docs.djangoproject.com/en/4.1/howto/static-files/ 120 | 121 | STATIC_URL = 'static/' 122 | 123 | # Default primary key field type 124 | # https://docs.djangoproject.com/en/4.1/ref/settings/#default-auto-field 125 | 126 | DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField' 127 | -------------------------------------------------------------------------------- /SUTT/urls.py: -------------------------------------------------------------------------------- 1 | """SUTT URL Configuration 2 | 3 | The `urlpatterns` list routes URLs to views. For more information please see: 4 | https://docs.djangoproject.com/en/4.1/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 path,include 18 | 19 | urlpatterns = [ 20 | path('', include('landingpage.urls')), 21 | path('polls/', include('polls.urls')), 22 | path('admin/', admin.site.urls), 23 | 24 | ] 25 | -------------------------------------------------------------------------------- /SUTT/wsgi.py: -------------------------------------------------------------------------------- 1 | """ 2 | WSGI config for SUTT 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/4.1/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', 'SUTT.settings') 15 | 16 | application = get_wsgi_application() 17 | -------------------------------------------------------------------------------- /landingpage/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/0xp3p3x0/Django-backend/10c2e66df9248ad5b0d7f281f158d5bebbd9acb3/landingpage/__init__.py -------------------------------------------------------------------------------- /landingpage/__pycache__/__init__.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/0xp3p3x0/Django-backend/10c2e66df9248ad5b0d7f281f158d5bebbd9acb3/landingpage/__pycache__/__init__.cpython-39.pyc -------------------------------------------------------------------------------- /landingpage/__pycache__/urls.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/0xp3p3x0/Django-backend/10c2e66df9248ad5b0d7f281f158d5bebbd9acb3/landingpage/__pycache__/urls.cpython-39.pyc -------------------------------------------------------------------------------- /landingpage/__pycache__/views.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/0xp3p3x0/Django-backend/10c2e66df9248ad5b0d7f281f158d5bebbd9acb3/landingpage/__pycache__/views.cpython-39.pyc -------------------------------------------------------------------------------- /landingpage/admin.py: -------------------------------------------------------------------------------- 1 | from django.contrib import admin 2 | 3 | # Register your models here. 4 | -------------------------------------------------------------------------------- /landingpage/apps.py: -------------------------------------------------------------------------------- 1 | from django.apps import AppConfig 2 | 3 | 4 | class LandingpageConfig(AppConfig): 5 | default_auto_field = 'django.db.models.BigAutoField' 6 | name = 'landingpage' 7 | -------------------------------------------------------------------------------- /landingpage/migrations/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/0xp3p3x0/Django-backend/10c2e66df9248ad5b0d7f281f158d5bebbd9acb3/landingpage/migrations/__init__.py -------------------------------------------------------------------------------- /landingpage/models.py: -------------------------------------------------------------------------------- 1 | from django.db import models 2 | 3 | # Create your models here. 4 | -------------------------------------------------------------------------------- /landingpage/tests.py: -------------------------------------------------------------------------------- 1 | from django.test import TestCase 2 | 3 | # Create your tests here. 4 | -------------------------------------------------------------------------------- /landingpage/urls.py: -------------------------------------------------------------------------------- 1 | from django.urls import path 2 | from . import views 3 | urlpatterns = [ 4 | path('', views.home, name ='home') 5 | ] 6 | -------------------------------------------------------------------------------- /landingpage/views.py: -------------------------------------------------------------------------------- 1 | from django.shortcuts import render 2 | from django.template import loader 3 | def home(request): 4 | return render(request,'landingpage/home.html') 5 | -------------------------------------------------------------------------------- /manage.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | """Django's command-line utility for administrative tasks.""" 3 | import os 4 | import sys 5 | 6 | 7 | def main(): 8 | """Run administrative tasks.""" 9 | os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'SUTT.settings') 10 | try: 11 | from django.core.management import execute_from_command_line 12 | except ImportError as exc: 13 | raise ImportError( 14 | "Couldn't import Django. Are you sure it's installed and " 15 | "available on your PYTHONPATH environment variable? Did you " 16 | "forget to activate a virtual environment?" 17 | ) from exc 18 | execute_from_command_line(sys.argv) 19 | 20 | 21 | if __name__ == '__main__': 22 | main() 23 | -------------------------------------------------------------------------------- /polls/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/0xp3p3x0/Django-backend/10c2e66df9248ad5b0d7f281f158d5bebbd9acb3/polls/__init__.py -------------------------------------------------------------------------------- /polls/__pycache__/__init__.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/0xp3p3x0/Django-backend/10c2e66df9248ad5b0d7f281f158d5bebbd9acb3/polls/__pycache__/__init__.cpython-39.pyc -------------------------------------------------------------------------------- /polls/__pycache__/admin.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/0xp3p3x0/Django-backend/10c2e66df9248ad5b0d7f281f158d5bebbd9acb3/polls/__pycache__/admin.cpython-39.pyc -------------------------------------------------------------------------------- /polls/__pycache__/apps.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/0xp3p3x0/Django-backend/10c2e66df9248ad5b0d7f281f158d5bebbd9acb3/polls/__pycache__/apps.cpython-39.pyc -------------------------------------------------------------------------------- /polls/__pycache__/models.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/0xp3p3x0/Django-backend/10c2e66df9248ad5b0d7f281f158d5bebbd9acb3/polls/__pycache__/models.cpython-39.pyc -------------------------------------------------------------------------------- /polls/__pycache__/urls.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/0xp3p3x0/Django-backend/10c2e66df9248ad5b0d7f281f158d5bebbd9acb3/polls/__pycache__/urls.cpython-39.pyc -------------------------------------------------------------------------------- /polls/__pycache__/views.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/0xp3p3x0/Django-backend/10c2e66df9248ad5b0d7f281f158d5bebbd9acb3/polls/__pycache__/views.cpython-39.pyc -------------------------------------------------------------------------------- /polls/admin.py: -------------------------------------------------------------------------------- 1 | from django.contrib import admin 2 | 3 | from .models import Question,Choice 4 | 5 | admin.site.register(Question) 6 | admin.site.register(Choice) 7 | -------------------------------------------------------------------------------- /polls/apps.py: -------------------------------------------------------------------------------- 1 | from django.apps import AppConfig 2 | 3 | 4 | class PollsConfig(AppConfig): 5 | default_auto_field = 'django.db.models.BigAutoField' 6 | name = 'polls' 7 | -------------------------------------------------------------------------------- /polls/migrations/0001_initial.py: -------------------------------------------------------------------------------- 1 | # Generated by Django 4.1.3 on 2022-11-30 06:04 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='Question', 17 | fields=[ 18 | ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), 19 | ('question_text', models.CharField(max_length=255)), 20 | ('pub_date', models.DateTimeField(verbose_name='Date Published')), 21 | ], 22 | ), 23 | migrations.CreateModel( 24 | name='Choice', 25 | fields=[ 26 | ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), 27 | ('choice_text', models.CharField(max_length=255)), 28 | ('votes', models.IntegerField(default=0)), 29 | ('question', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='polls.question')), 30 | ], 31 | ), 32 | ] 33 | -------------------------------------------------------------------------------- /polls/migrations/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/0xp3p3x0/Django-backend/10c2e66df9248ad5b0d7f281f158d5bebbd9acb3/polls/migrations/__init__.py -------------------------------------------------------------------------------- /polls/migrations/__pycache__/0001_initial.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/0xp3p3x0/Django-backend/10c2e66df9248ad5b0d7f281f158d5bebbd9acb3/polls/migrations/__pycache__/0001_initial.cpython-39.pyc -------------------------------------------------------------------------------- /polls/migrations/__pycache__/__init__.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/0xp3p3x0/Django-backend/10c2e66df9248ad5b0d7f281f158d5bebbd9acb3/polls/migrations/__pycache__/__init__.cpython-39.pyc -------------------------------------------------------------------------------- /polls/models.py: -------------------------------------------------------------------------------- 1 | from django.db import models 2 | import datetime 3 | from django.db import models 4 | from django.utils import timezone 5 | class Question(models.Model): 6 | question_text = models.CharField(max_length=255) 7 | pub_date = models.DateTimeField('Date Published') 8 | def __str__(self): 9 | return self.question_text 10 | def was_published_recently(self): 11 | return self.pub_date >= timezone.now() - datetime.timedelta(days=1) 12 | class Choice(models.Model): 13 | question = models.ForeignKey(Question, on_delete=models.CASCADE) 14 | choice_text = models.CharField(max_length=255) 15 | votes = models.IntegerField(default=0) 16 | def __str__(self): 17 | return self.choice_text 18 | -------------------------------------------------------------------------------- /polls/templates/landingpage/home.html: -------------------------------------------------------------------------------- 1 | 2 |
3 | 4 |This is a Django polling app
12 | 13 | 14 | View Available Polls 15 |12 | {{ error_message }} 13 |
14 | 15 | {% endif %} 16 | 17 | 28 | 29 | 30 | -------------------------------------------------------------------------------- /polls/templates/polls/home.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 |No polls available
20 | {% endif %} 21 | 22 | 23 | -------------------------------------------------------------------------------- /polls/templates/polls/results.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 |