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.urls import reverse
class Course(models.Model):
code = models.CharField(max_length = 10)
......@@ -20,4 +21,7 @@ class Assignment(models.Model):
super(Assignment, self).save(*args, **kwargs)
def __str__(self):
return self.name
\ No newline at end of file
return self.name
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 .views import index
from .import views
from .views import (AssignmentDetailView, AssignmentCreateView, AssignmentUpdateView)
urlpatterns = [
path('', index, name = 'index'),
]
app_name = "assignments"
\ No newline at end of file
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"),
path('assignments/<int:pk>/edit/', AssignmentUpdateView.as_view(), name="assignment-edit"),
]
\ 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
def index(request):
assignments = Assignment.objects.all()
def assignments(request):
return render(request, 'assignments/assignments.html', {'assignments': Assignment.objects.all()})
response = "Widget's Assignment Page<br><br>"
for assignment in assignments:
response += "Assignment Name: {}<br>Description: {}<br>Perfect Score: {}<br>Passing Score: {}<br>Course/Section: {}<br><br>".format(
assignment.name,
assignment.description,
assignment.perfect_score,
assignment.passing_score,
assignment.course
)
return HttpResponse(response)
\ No newline at end of file
class AssignmentDetailView(DetailView):
model = Assignment
template_name = 'assignments/assignment-details.html'
class AssignmentCreateView(CreateView):
model = Assignment
fields = '__all__'
template_name = 'assignments/assignment-add.html'
class AssignmentUpdateView(UpdateView):
model = Assignment
fields = '__all__'
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/
"""
from pathlib import Path
import os
# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent
......@@ -59,7 +60,7 @@ ROOT_URLCONF = 'widget_bigdjangoenergy.urls'
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [],
'DIRS': [os.path.join(BASE_DIR, 'templates')],
'APP_DIRS': True,
'OPTIONS': {
'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