Added Course model under Assignments app, view displays all assignments

parent fb84ff44
from django.contrib import admin
from .models import Assignment
from .models import Course
admin.site.register(Assignment)
admin.site.register(Course)
# Generated by Django 4.0.3 on 2022-03-22 14:15
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('assignments', '0002_alter_assignment_max_points'),
]
operations = [
migrations.CreateModel(
name='Course',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('course_code', models.CharField(max_length=10)),
('course_title', models.CharField(max_length=120)),
('section', models.CharField(max_length=3)),
],
),
]
# Generated by Django 4.0.3 on 2022-03-22 14:16
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('assignments', '0003_course'),
]
operations = [
migrations.AddField(
model_name='assignment',
name='course',
field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, to='assignments.course'),
),
migrations.AddField(
model_name='assignment',
name='passing_score',
field=models.IntegerField(default=6),
),
]
......@@ -5,3 +5,20 @@ class Assignment(models.Model):
name = models.CharField(max_length=120)
description = models.TextField(blank=True)
max_points = models.IntegerField(default=10)
passing_score = models.IntegerField(default=6)
def save(self, *args, **kwargs):
self.passing_score = int(0.6*self.max_points)
super(Assignment, self).save()
course = models.ForeignKey(
'Course',
on_delete=models.CASCADE,
null=True,
)
class Course(models.Model):
course_code = models.CharField(max_length=10)
course_title = models.CharField(max_length=120)
section = models.CharField(max_length=3)
<html>
<head>
<title>Assignments</title>
</head>
<body>
ASSIGNMENTS: <br>
{% for assignment in all_assignments %}
Assignment Name: {{ assignment.name }}<br>
Description: {% if assignment.description != None and assignment.description != '' %}{{ assignment.description }}{% else %}No description provided.{% endif %}<br>
Perfect Score: {{ assignment.max_points }}<br>
Passing Score: {{ assignment.passing_score }}<br>
Course/Section: {{ assignment.course.course_code }} {{ assignment.course.course_title }} {{ assignment.course.section }}<br><br>
{% endfor %}
</body>
</html>
\ No newline at end of file
from django.urls import path
from .views import index
from .views import assignments_view
urlpatterns = [
path('', index, name='index'),
path('', assignments_view, name='assignments_view'),
]
app_name = "assignments"
from django.shortcuts import render
from django.http import HttpResponse
from .models import Assignment
def index(request):
return HttpResponse("This is the Assignments page!")
def assignments_view(request):
objects_set = {
"all_assignments": [obj for obj in Assignment.objects.all()]
}
return render(request, "assignments_template.html", objects_set)
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