Assignment App

parent 1613af84
from django.forms import ModelForm
from .models import Assignment
class AssignmentForm(ModelForm):
class Meta:
model = Assignment
fields = '__all__'
\ No newline at end of file
from django.db import models from django.db import models
from django.urls import reverse
class Course(models.Model): class Course(models.Model):
code = models.CharField(max_length = 10) code = models.CharField(max_length = 10)
...@@ -20,4 +21,7 @@ class Assignment(models.Model): ...@@ -20,4 +21,7 @@ class Assignment(models.Model):
super(Assignment, self).save(*args, **kwargs) super(Assignment, self).save(*args, **kwargs)
def __str__(self): def __str__(self):
return self.name return self.name
\ No newline at end of file
def get_absolute_url(self):
return reverse("assignment-details", kwargs={'pk': self.pk})
\ No newline at end of file
{% extends 'base.html' %}
{% load static %}
{% block title %}Add Assignment:{% endblock %}
{% block content %}
<p>Add a new assignment:</p>
<form method="POST">
{% csrf_token %}
{{ form.as_p }}
<input type="Submit" value="Save New Assignment">
</form>
{% endblock %}
{% extends 'base.html' %}
{% load static %}
{% block title %}{{ object.name }}{% endblock %}
{% block heading %}{{ object.name }}{% endblock %}
{% block content %}
<p>{{ object.course.code }} {{ object.course.title }} - {{ object.course.section }}</p>
<p>Description: {{ object.description }}</p>
<p>Perfect Score: {{ object.perfect_score }}</p>
<p>Passing Score: {{ object.passing_score }}</p>
<input type="button" value="Edit Assignment" onclick="location.href='{% url 'assignment-edit' object.pk %}'"/>
{% endblock %}
\ No newline at end of file
{% extends 'base.html' %}
{% load static %}
{% block title %}Edit Assignment{% endblock %}
{% block content %}
<p>Edit Assignment:</p>
<form method ="POST">
{% csrf_token %}
{{ form.as_p }}
<input type ="Submit" value="Save Changes to Assignment">
</form>
{% endblock %}
{% extends 'base.html' %}
{% load static %}
{% block title %}Widget's Assignments{% endblock %}
{% block heading %}Welcome to Widget's Assignments!{% endblock %}
{% block content %}
<p>Assignments posts:</p>
{% for assignment in assignments%}
<p><a href="{{assignment.get_absolute_url}}">{{ assignment.name }}</a></p>
{% endfor %}
<input type="button" value="New Assignment" onclick="location.href='{% url 'assignment-add' %}'"/>
{% endblock %}
{% block links %}
<p><a href="http://localhost:8000/dashboard/">Dashboard</a></p>
<p><a href="http://localhost:8000/announcements/">Announcement</a></p>
<p><a href="http://localhost:8000/forum/">Forum</a></p>
<p><a href="http://localhost:8000/calendar/">Calendar</a></p>
{% endblock %}
\ No newline at end of file
from django.urls import path from django.urls import path
from .import views
from .views import index from .views import (AssignmentDetailView, AssignmentCreateView, AssignmentUpdateView)
urlpatterns = [ urlpatterns = [
path('', index, name = 'index'), path('', views.assignments, name="assignments"),
] path('assignments/<int:pk>/details/', AssignmentDetailView.as_view(), name="assignment-details"),
path('assignment/add/', AssignmentCreateView.as_view(), name="assignment-add"),
app_name = "assignments" path('assignments/<int:pk>/edit/', AssignmentUpdateView.as_view(), name="assignment-edit"),
\ No newline at end of file ]
\ No newline at end of file
from django.http import HttpResponse 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 .models import Assignment
def index(request): def assignments(request):
assignments = Assignment.objects.all() return render(request, 'assignments/assignments.html', {'assignments': Assignment.objects.all()})
response = "Widget's Assignment Page<br><br>" class AssignmentDetailView(DetailView):
for assignment in assignments: model = Assignment
response += "Assignment Name: {}<br>Description: {}<br>Perfect Score: {}<br>Passing Score: {}<br>Course/Section: {}<br><br>".format( template_name = 'assignments/assignment-details.html'
assignment.name,
assignment.description, class AssignmentCreateView(CreateView):
assignment.perfect_score, model = Assignment
assignment.passing_score, fields = '__all__'
assignment.course template_name = 'assignments/assignment-add.html'
)
class AssignmentUpdateView(UpdateView):
return HttpResponse(response) model = Assignment
fields = '__all__'
\ No newline at end of file template_name = 'assignments/assignment-edit.html'
\ No newline at end of file
<html>
<head>
<title>{% block title%}{% endblock %}</title>
</head>
<body>
<div id="heading">
<h1>{% block heading %}{% endblock %}</h1>
</div>
<div id="content">
{% block content %}{% endblock %}
</div>
<div id="links">
{% block links %}{% endblock %}
</div>
</body>
</html>
...@@ -11,6 +11,7 @@ https://docs.djangoproject.com/en/3.2/ref/settings/ ...@@ -11,6 +11,7 @@ https://docs.djangoproject.com/en/3.2/ref/settings/
""" """
from pathlib import Path from pathlib import Path
import os
# Build paths inside the project like this: BASE_DIR / 'subdir'. # Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent BASE_DIR = Path(__file__).resolve().parent.parent
...@@ -59,7 +60,7 @@ ROOT_URLCONF = 'widget_bigdjangoenergy.urls' ...@@ -59,7 +60,7 @@ ROOT_URLCONF = 'widget_bigdjangoenergy.urls'
TEMPLATES = [ TEMPLATES = [
{ {
'BACKEND': 'django.template.backends.django.DjangoTemplates', 'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [], 'DIRS': [os.path.join(BASE_DIR, 'templates')],
'APP_DIRS': True, 'APP_DIRS': True,
'OPTIONS': { 'OPTIONS': {
'context_processors': [ 'context_processors': [
......
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