Commit d822d5c8 authored by Rafa Mendoza's avatar Rafa Mendoza

assignment db implemented

parent 58924902
File added
from django.contrib import admin
from .models import Assignment, Course
class AssignmentAdmin(admin.ModelAdmin):
model = Assignment
list_display = ('assignment_name', 'description', 'course', 'perfect_score',)
search_fields = ('assignment_name', 'description', 'course', 'perfect_score',)
list_filter = ('assignment_name', 'description', 'course', 'perfect_score',)
class CourseAdmin(admin.ModelAdmin):
model = Course
list_display = ('code', 'title', 'section',)
search_fields = ('code', 'title', 'section',)
list_filter = ('code', 'title', 'section',)
admin.site.register(Assignment, AssignmentAdmin)
admin.site.register(Course, CourseAdmin)
from django.apps import AppConfig
class AssignmentsConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'assignments'
# Generated by Django 4.1.7 on 2023-03-05 14:44
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
initial = True
dependencies = [
]
operations = [
migrations.CreateModel(
name='Course',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('code', models.CharField(max_length=10)),
('title', models.CharField(max_length=100)),
('section', models.CharField(max_length=3)),
],
),
migrations.CreateModel(
name='Assignment',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('assignment_name', models.CharField(max_length=50)),
('description', models.TextField()),
('perfect_score', models.IntegerField()),
('course', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='assignments.course')),
],
),
]
from django.db import models
class Course(models.Model):
code = models.CharField(max_length=10)
title = models.CharField(max_length=100)
section = models.CharField(max_length=3)
def __str__(self):
return '''{}, {}, {}'''.format(
self.code,
self.title,
self.section,
)
class Assignment(models.Model):
assignment_name = models.CharField(max_length=50)
description = models.TextField()
course = models.ForeignKey(Course, on_delete=models.CASCADE)
perfect_score = models.IntegerField()
def __str__(self):
return '''{}, {}, {}, {}'''.format(
self.assignment_name,
self.description,
self.course,
self.perfect_score,
)
\ No newline at end of file
from django.test import TestCase
# Create your tests here.
from django.urls import path
from .views import index
urlpatterns = [
path('', index, name= 'index'),
]
app_name = "assignments"
\ No newline at end of file
from django.http import HttpResponse
from .models import Assignment
def index(request):
return_string = "<p>Widget's Assignment Page</p>"
for a in Assignment.objects.all():
return_string += '''Assignment Name: {} <br>Description: {}
<br>Perfect Score: {} <br>Passing Score: {}
<br>Course/Section: {} {}-{}<br><br>'''.format(
a.assignment_name,
a.description,
a.perfect_score,
int(a.perfect_score * 0.60),
a.course.code,
a.course.title,
a.course.section,
)
html_string = '<html><body>{}</body></html>'.format(return_string)
return HttpResponse(html_string)
......@@ -40,6 +40,7 @@ INSTALLED_APPS = [
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'assignments',
]
MIDDLEWARE = [
......
......@@ -14,8 +14,9 @@ Including another URLconf
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
"""
from django.contrib import admin
from django.urls import path
from django.urls import include, path
urlpatterns = [
path('assignments/', include('assignments.urls', namespace="assignments")),
path('admin/', admin.site.urls),
]
Markdown is supported
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