Did my part for Assignments

parent 36e51a79
No preview for this file type
from django.contrib import admin
from .models import WidgetUser, Forum, Announcement, Assignment
from .models import WidgetUser, Forum, Announcement, Assignment, Course
# Classes
......@@ -54,6 +54,8 @@ class ForumAdmin(admin.ModelAdmin):
}),
]
class AssignmentInline(admin.TabularInline):
model = Assignment
class AssignmentAdmin(admin.ModelAdmin):
model = Assignment
......@@ -70,7 +72,33 @@ class AssignmentAdmin(admin.ModelAdmin):
'name',
'description',
'max_points'
'max_points',
'passing_score'
]
}
)
]
class CourseAdmin(admin.ModelAdmin):
model = Course
search_fields = ('course_code', 'course_title', 'section')
list_display = ('course_code', 'course_title', 'section')
list_filter = ('course_code', 'course_title', 'section')
fieldsets = [
('Course Data', {
'fields': [
'course_code',
'course_title',
'section'
]
......@@ -80,6 +108,8 @@ class AssignmentAdmin(admin.ModelAdmin):
]
inlines = [AssignmentInline,]
......@@ -90,3 +120,4 @@ admin.site.register(WidgetUser, WidgetUserAdmin)
admin.site.register(Forum, ForumAdmin)
admin.site.register(Announcement, AnnouncementAdmin)
admin.site.register(Assignment, AssignmentAdmin)
admin.site.register(Course, CourseAdmin)
\ No newline at end of file
# Generated by Django 4.0.3 on 2022-04-08 07:16
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
initial = True
dependencies = [
]
operations = [
migrations.CreateModel(
name='Announcement',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('announcement_title', models.CharField(max_length=50)),
('announcement_body', models.CharField(max_length=200)),
('pub_date', models.DateTimeField(auto_now_add=True)),
],
),
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=100)),
('section', models.CharField(max_length=3)),
],
),
migrations.CreateModel(
name='Forum',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('post_title', models.CharField(max_length=50)),
('post_body', models.CharField(max_length=100)),
('pub_date', models.DateTimeField(auto_now_add=True)),
],
),
migrations.CreateModel(
name='WidgetUser',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('first_name', models.CharField(max_length=100)),
('middle_name', models.CharField(max_length=100)),
('last_name', models.CharField(max_length=100)),
],
),
migrations.CreateModel(
name='Assignment',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(max_length=100)),
('description', models.CharField(max_length=200)),
('max_points', models.IntegerField()),
('course', models.ForeignKey(default=1, on_delete=django.db.models.deletion.CASCADE, to='widget_group3.course')),
],
),
]
......@@ -43,23 +43,28 @@ class Forum(models.Model):
def get_absolute_url(self):
return reverse('forum', args=[(self.post_title)])
class Course(models.Model):
course_code = models.CharField(max_length = 10)
course_title = models.CharField(max_length = 100)
section = models.CharField(max_length = 3)
def __str__(self):
return '{} {} {}'.format(self.course_code, self.course_title, self.section)
class Assignment(models.Model):
name = models.CharField(max_length = 100)
description = models.CharField(max_length = 200)
max_points = models.IntegerField()
passing_score = max_points * .6
course = models.ForeignKey(Course, on_delete = models.CASCADE, default = 1)
def __str__(self):
return '{} <br> Description: {} <br> Perfect Score: {} <br> Passing Score: {}'.format(self.name, self.description, self.max_points, self.passing_score)
def get_absolute_url(self):
return reverse('assignment', args=[(self.full_assignment)])
class Course(models.Model):
course_code = models.CharField(max_length = 10)
course_title = models.CharField(max_length = 100)
section = models.CharField(max_length = 3)
assignment = models.ForeignKey(Assignment, on_delete = models.CASCADE)
@property
def full_assignment(self):
return '{} {} {}'.format(self.name, self.description, self.max_points)
@property
def passing_score(self):
return self.max_points * .6
def __str__(self):
return '{} {} {}'.format(self.course_code, self.course_title, self.section)
......@@ -6,7 +6,16 @@ def homepage(request):
def assignments(request):
assignments = Assignment.objects.all()
output = "Assignments: <br>" + "<br>".join([str(details) for details in assignments])
courses = Course.objects.all()
output = "ASSIGNMENTS:\n" + "\n".join(
['Assignment Name: {}\n Description: {}\n Perfect Score: {}\n Passing Score: {}\n Course/Section: {}'
.format(str(assignment.name),
str(assignment.description),
str(assignment.max_points),
str(assignment.passing_score),
str(assignment.course))
for assignment in assignments]
)
return HttpResponse(output, content_type = "text/plain")
def announcements(request):
......
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