Commit 7b4fc362 authored by Albert Gagalac's avatar Albert Gagalac

implemented assignment-add.html features

parent 6c4e976c
from django.db import models from django.db import models
from django.urls import reverse
from django.core.validators import RegexValidator from django.core.validators import RegexValidator
# Create your models here. # Create your models here.
...@@ -24,6 +25,9 @@ class Assignment(models.Model): ...@@ -24,6 +25,9 @@ class Assignment(models.Model):
course = models.ForeignKey(Course, on_delete=models.CASCADE) course = models.ForeignKey(Course, on_delete=models.CASCADE)
perfect_score = models.PositiveIntegerField(default=0) perfect_score = models.PositiveIntegerField(default=0)
def get_absolute_url(self):
return reverse('assignments:assignment-details', kwargs={'pk' : self.pk})
def __str__(self): def __str__(self):
return self.name return self.name
......
{% extends 'base.html' %}
{% load static %}
{% block title %} Add Assignment {% endblock %}
{% block content %}
<h2>Add a new Assignment:</h2>
<p>
<form action='' method="POST">
{% csrf_token %}
Name: {{form.name}}<br><br>
Description: <br> {{form.description}}<br><br>
Course: {{form.course}}<br><br>
Perfect Score: {{form.perfect_score}}<br><br>
<input type="submit" value="Add Assignment">
</form>
</p>
{% endblock %}
\ No newline at end of file
{% extends 'base.html' %} {% extends 'base.html' %}
{% load static %} {% load static %}
{% block title %} Widget's Assignments {% endblock %}
{% block content %} {% block content %}
<h2>{{assignment.name}}</h2> <h2> Welcome to Widget's Assignments! </h2>
<h3>{{assignment.course}}</h3>
{% for data in assignment %} {% for data in assignment %}
<p> <p> <a href="{{ data.get_absolute_url }}">{{ data }}</a></p>
Description: {{data.description}}<br>
Perfect Score: {{data.perfect_score}}<br>
Passing Score: {{data.passing_score}}<br>
</p>
{% endfor %} {% endfor %}
{% endblock %} {% endblock %}
\ No newline at end of file
from django.urls import path from django.urls import path
from .views import pageview, AssignmentDetailView from .views import pageview, AssignmentDetailView, AssignmentCreateView
urlpatterns = [ urlpatterns = [
path('', pageview, name='pageview'), path('', pageview, name='pageview'),
path('<int:pk>/details', AssignmentDetailView.as_view(), name='assignment-details') path('<int:pk>/details', AssignmentDetailView.as_view(), name='assignment-details'),
path('add', AssignmentCreateView.as_view(), name='assignment-add'),
] ]
app_name = "assignments" app_name = "assignments"
\ No newline at end of file
...@@ -15,3 +15,9 @@ class AssignmentDetailView(DetailView): ...@@ -15,3 +15,9 @@ class AssignmentDetailView(DetailView):
course = assignment.course course = assignment.course
return render(request, 'assignments/assignment-details.html', {'assignment': assignment, 'course': course}) return render(request, 'assignments/assignment-details.html', {'assignment': assignment, 'course': course})
class AssignmentCreateView(CreateView):
model = Assignment
fields = '__all__'
template_name = 'assignments/assignment-add.html'
\ No newline at end of file
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