Commit bc2aecd9 authored by Raul Jarod Conanan's avatar Raul Jarod Conanan

Deleted assignments/__pycache__/__init__.cpython-311.pyc,...

Deleted assignments/__pycache__/__init__.cpython-311.pyc, assignments/__pycache__/__init__.cpython-38.pyc, assignments/__pycache__/admin.cpython-311.pyc, assignments/__pycache__/admin.cpython-38.pyc, assignments/__pycache__/apps.cpython-311.pyc, assignments/__pycache__/apps.cpython-38.pyc, assignments/__pycache__/forms.cpython-38.pyc, assignments/__pycache__/models.cpython-311.pyc, assignments/__pycache__/models.cpython-38.pyc, assignments/__pycache__/urls.cpython-311.pyc, assignments/__pycache__/urls.cpython-38.pyc, assignments/__pycache__/views.cpython-311.pyc, assignments/__pycache__/views.cpython-38.pyc, assignments/migrations/__pycache__/0001_initial.cpython-311.pyc, assignments/migrations/__pycache__/0001_initial.cpython-38.pyc, assignments/migrations/__pycache__/0002_alter_assignment_course.cpython-311.pyc, assignments/migrations/__pycache__/0002_alter_assignment_course.cpython-38.pyc, assignments/migrations/__pycache__/__init__.cpython-311.pyc, assignments/migrations/__pycache__/__init__.cpython-38.pyc, assignments/migrations/0001_initial.py, assignments/migrations/0002_alter_assignment_course.py, assignments/migrations/__init__.py, assignments/__init__.py, assignments/admin.py, assignments/apps.py, assignments/forms.py, assignments/models.py, assignments/tests.py, assignments/urls.py, assignments/views.py files
parent 5deed8ac
from django.contrib import admin
from .models import Assignment, Course
class AssignmentAdmin(admin.ModelAdmin):
model = Assignment
class CourseAdmin(admin.ModelAdmin):
model = Course
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'
from django.forms import ModelForm
from .models import Assignment
from django import forms
class AssignmentForm(ModelForm):
class Meta:
model = Assignment
fields = "__all__"
labels = {
'name': '',
'description': '',
'course': 'Course: ',
'perfect_score': '',
}
widgets = {
'name': forms.TextInput(attrs={'class': 'form-control', 'placeholder': 'Assignment Name'}),
'description': forms.Textarea(attrs={'class': 'form-control', 'placeholder': 'Description'}),
'course': forms.Select(attrs={'class': 'form-control', 'placeholder': 'Course'}),
'perfect_score': forms.NumberInput(attrs={'class': 'form-control', 'placeholder': 'Perfect Score'}),
'passing_score': forms.HiddenInput(),
}
\ No newline at end of file
# Generated by Django 4.1.7 on 2023-03-04 17:11
from django.db import migrations, models
class Migration(migrations.Migration):
initial = True
dependencies = [
]
operations = [
migrations.CreateModel(
name='Assignment',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(blank=True, max_length=255, null=True)),
('description', models.TextField(blank=True, null=True)),
('course', models.CharField(blank=True, max_length=255, null=True)),
('perfect_score', models.IntegerField(blank=True, null=True)),
('passing_score', models.IntegerField(blank=True, null=True)),
],
),
migrations.CreateModel(
name='Course',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('code', models.CharField(blank=True, max_length=10, null=True)),
('title', models.CharField(blank=True, max_length=255, null=True)),
('section', models.CharField(blank=True, max_length=3, null=True)),
],
),
]
# Generated by Django 4.1.7 on 2023-03-04 17:27
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('assignments', '0001_initial'),
]
operations = [
migrations.AlterField(
model_name='assignment',
name='course',
field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, to='assignments.course'),
),
]
from django.db import models
from django.urls import reverse
class Course(models.Model):
code = models.CharField(max_length=10, blank=True, null=True)
title = models.CharField(max_length=255, blank=True, null=True)
section = models.CharField(max_length=3, blank=True, null=True)
def __str__(self):
return self.code + '-' + self.section
class Assignment(models.Model):
name = models.CharField(max_length=255, blank=True, null=True)
description = models.TextField(blank=True, null=True)
course = models.ForeignKey(Course, on_delete=models.CASCADE, null=True)
perfect_score = models.IntegerField(blank=True, null=True)
passing_score = models.IntegerField(blank=True, null=True)
def save(self, *args, **kwargs):
self.passing_score = int(self.perfect_score * 0.60)
super(Assignment, self).save(*args, **kwargs)
def __str__(self):
return self.name
def get_absolute_url(self):
return reverse('assignments:assignments-item', kwargs={'pk': self.pk})
def get_update_url(self):
return reverse('assignments:assignments-edit', kwargs={'pk': self.pk})
from django.test import TestCase
# Create your tests here.
from django.urls import path
from .views import (
index, AssignmentDetailsView,
AddAssignmentView, EditAssignmentView
)
urlpatterns = [
path('', index, name='index'),
path('add/', AddAssignmentView.as_view(), name='assignments-add'),
path('<int:pk>/edit/', EditAssignmentView.as_view(), name='assignments-edit'),
path('<int:pk>/details/', AssignmentDetailsView.as_view(), name='assignments-item'),
]
app_name = "assignments"
from django.shortcuts import render
from django.views.generic.detail import DetailView
from django.views.generic.edit import CreateView, UpdateView
from .models import Assignment
from .forms import AssignmentForm
class AssignmentDetailsView(DetailView):
model = Assignment
template_name = 'assignments/assignment-details.html'
class AddAssignmentView(CreateView):
model = Assignment
form_class = AssignmentForm
template_name = 'assignments/assignment-add.html'
class EditAssignmentView(UpdateView):
model = Assignment
form_class = AssignmentForm
template_name = 'assignments/assignment-edit.html'
def index(request):
assignments = Assignment.objects.all()
context = {
'assignments': assignments
}
return render(request, 'assignments/assignments.html', context)
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