Commit 6d234d49 authored by Mayank Kava's avatar Mayank Kava
Browse files

Pushing the repository to github

parents
File added
"""
ASGI config for ex09 project.
It exposes the ASGI callable as a module-level variable named ``application``.
For more information on this file, see
https://docs.djangoproject.com/en/3.0/howto/deployment/asgi/
"""
import os
from django.core.asgi import get_asgi_application
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'ex09.settings')
application = get_asgi_application()
"""
Django settings for ex09 project.
Generated by 'django-admin startproject' using Django 3.0.7.
For more information on this file, see
https://docs.djangoproject.com/en/3.0/topics/settings/
For the full list of settings and their values, see
https://docs.djangoproject.com/en/3.0/ref/settings/
"""
import os
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/3.0/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = ')2urkqj3vcp6z3w67l=h5wxx3oo+8s*)j+ta*h7=mb*giof^xv'
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
ALLOWED_HOSTS = ['192.168.0.112', 'localhost','127.0.0.1']
# Application definition
INSTALLED_APPS = [
'university.apps.UniversityConfig',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
]
MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'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 = 'ex09.urls'
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [os.path.join(BASE_DIR,'templates')],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
]
WSGI_APPLICATION = 'ex09.wsgi.application'
# Database
# https://docs.djangoproject.com/en/3.0/ref/settings/#databases
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
}
}
# Password validation
# https://docs.djangoproject.com/en/3.0/ref/settings/#auth-password-validators
AUTH_PASSWORD_VALIDATORS = [
{
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
},
]
# Internationalization
# https://docs.djangoproject.com/en/3.0/topics/i18n/
LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'UTC'
USE_I18N = True
USE_L10N = True
USE_TZ = True
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/3.0/howto/static-files/
STATIC_URL = '/static/'
"""ex09 URL Configuration
The `urlpatterns` list routes URLs to views. For more information please see:
https://docs.djangoproject.com/en/3.0/topics/http/urls/
Examples:
Function views
1. Add an import: from my_app import views
2. Add a URL to urlpatterns: path('', views.home, name='home')
Class-based views
1. Add an import: from other_app.views import Home
2. Add a URL to urlpatterns: path('', Home.as_view(), name='home')
Including another URLconf
1. Import the include() function: from django.urls import include, path
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
"""
from django.contrib import admin
from django.conf.urls import include,url
from django.urls import path
urlpatterns = [
path('admin/', admin.site.urls),
path('', include('university.urls')),
]
"""
WSGI config for ex09 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/3.0/howto/deployment/wsgi/
"""
import os
from django.core.wsgi import get_wsgi_application
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'ex09.settings')
application = get_wsgi_application()
#!/usr/bin/env python
"""Django's command-line utility for administrative tasks."""
import os
import sys
def main():
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'ex09.settings')
try:
from django.core.management import execute_from_command_line
except ImportError as exc:
raise ImportError(
"Couldn't import Django. Are you sure it's installed and "
"available on your PYTHONPATH environment variable? Did you "
"forget to activate a virtual environment?"
) from exc
execute_from_command_line(sys.argv)
if __name__ == '__main__':
main()
from django.contrib import admin
from .models import Student, Professor, Exam, Grade
admin.site.register(Student)
admin.site.register(Professor)
admin.site.register(Exam)
admin.site.register(Grade)
# Register your models here.
from django.apps import AppConfig
class UniversityConfig(AppConfig):
name = 'university'
# Generated by Django 3.0.7 on 2020-07-17 18:57
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
initial = True
dependencies = [
]
operations = [
migrations.CreateModel(
name='Exam',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('topic', models.CharField(max_length=50)),
],
),
migrations.CreateModel(
name='Professor',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('prf_name', models.CharField(max_length=100)),
],
),
migrations.CreateModel(
name='Student',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('st_name', models.CharField(max_length=50)),
('matriculation_nr', models.CharField(max_length=10)),
],
),
migrations.CreateModel(
name='Grade',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('grade', models.CharField(max_length=3)),
('exam', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='university.Exam')),
('student', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='university.Student')),
],
),
migrations.AddField(
model_name='exam',
name='Participants',
field=models.ManyToManyField(to='university.Student'),
),
migrations.AddField(
model_name='exam',
name='docent',
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='university.Professor'),
),
]
from django.db import models
# Create your models here.
class Student(models.Model):
st_name = models.CharField(max_length=50)
matriculation_nr = models.CharField(max_length=10)
def __str__(self):
return self.st_name
pass
class Professor(models.Model):
prf_name = models.CharField(max_length=100)
def __str__(self):
return self.prf_name
pass
class Exam(models.Model):
topic = models.CharField(max_length=50)
docent = models.ForeignKey(Professor, on_delete=models.CASCADE)
Participants = models.ManyToManyField(Student)
def __str__(self):
return self.topic
pass
class Grade(models.Model):
grade = models.CharField(max_length=3)
student = models.ForeignKey(Student,on_delete=models.CASCADE)
exam = models.ForeignKey(Exam,on_delete=models.CASCADE)
def __str__(self):
return f'{self.student.st_name} [{self.grade}]'
pass
<!DOCTYPE html>
<html lang="en">
<head>
<title>Student List</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.0/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.0/umd/popper.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.0/js/bootstrap.min.js"></script>
</head>
<body>
<div class="jumbotron text-center">
<h1>{%block title%}University{%endblock%}</h1>
</div>
<nav class="navbar navbar-expand-sm bg-dark navbar-dark">
<a class="navbar-brand" href="/">Overview</a>
<div class="collapse navbar-collapse" id="collapsibleNavbar">
<ul class="navbar-nav">
<li class="nav-item">
<a class="nav-link" href="/professors">Professors</a>
</li>
<li class="nav-item">
<a class="nav-link" href="/students">Students</a>
</li>
<li class="nav-item">
<a class="nav-link" href="/exams">Exams</a>
</li>
<li class="nav-item">
<a class="nav-link" href="/admin">Admin</a>
</li>
</ul>
</div>
</nav>
<div class="container mt-1">
{% block contain %}
{% endblock %}
</div>
</body>
</html>
{% extends "university/base.html" %}
{%block title%}Exams{%endblock%}
{% block contain %}
<table class="table">
<thead class="thead-dark">
<tr>
<th scope="col">Topic</th>
<th scope="col">Professor</th>
<th scope="col">Students</th>
</tr>
</thead>
<tbody>
{%for item in all_exam%}
<tr>
<td>{{item.topic}}</td>
<td>{{item.docent.prf_name}}</td>
<td>{%for std in item.Participants.all%}{{std.st_name}}
{%endfor%}
</td>
</tr>
{%endfor%}
</tbody>
</table>
{% endblock %}
\ No newline at end of file
{% extends "university/base.html" %}
{% block contain %}
{% endblock %}
{% extends "university/base.html" %}
{%block title%}Professor{%endblock%}
{% block contain %}
<table class="table table-striped table-sm">
<thead class="thead-dark">
<tr>
<th>Professors Name</th>
</tr>
</thead>
<tbody>
{% for professor in all_professor %}
<tr>
<td>{{ professor.prf_name }}</td>
</tr>
{% endfor %}
</tbody>
</table>
{% endblock %}
{% extends "university/base.html" %}
{%block title%}Students{%endblock%}
{% block contain %}
<table class="table table-striped table-sm">
<thead class="thead-dark">
<tr>
<th>Student Name</th>
<th>Matriculation Number</th>
</tr>
</thead>
<tbody>
{% for student in all_student %}
<tr>
<td>{{ student.st_name }}</td>
<td>{{ student.matriculation_nr }}</td>
</tr>
{% endfor %}
</tbody>
</table>
{% endblock %}
from django.test import TestCase
# Create your tests here.
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment