Commit 385eee3d authored by Ciella's avatar Ciella

Created views and updated URLs

parent 98014e12
from django.urls import path from django.urls import path
from .views import index from .views import assignments_view, AssignmentDetailView, AssignmentCreateView, AssignmentUpdateView
urlpatterns = [ urlpatterns = [
path('', index, name='index'), path('assignments/', assignments_view, name='assignments_view'),
path('assignments/<int:pk>/details/', AssignmentDetailView.as_view(), name='assignment-details'),
path('assignments/add/', AssignmentCreateView.as_view(), name='assignment-add'),
path('assignments/<int:pk>/edit/', AssignmentUpdateView.as_view(), name='assignment-edit'),
] ]
app_name = 'assignments' app_name = 'assignments'
\ No newline at end of file
from django.shortcuts import render from django.shortcuts import render
from django.http import HttpResponse from django.views.generic.detail import DetailView
from django.views.generic.edit import CreateView, UpdateView
from .models import Assignment from .models import Assignment
# Create your views here.
def index(request):
return_string = '<p>Widget\'s Assignments Page<br>'
for work in Assignment.objects.all(): def assignments_view(request):
work_string = '<br>Assignment Name: {}<br>Description: {}<br>Perfect Score: {}<br>Passing Score: {}<br>Course/Section: {} {}-{}<br>'.format( tasks = Assignment.objects.all()
work.name, work.description, work.perfect_score, work.passing_score, work.course.code, work.course.title, work.course.section) context = {'tasks' : tasks}
return_string += work_string return render(request, 'assignments/assignments.html')
return_string += '</p>'
html_string = '<html><body>{}</body></html>'.format(return_string)
return HttpResponse(html_string) class AssignmentDetailView(DetailView):
\ No newline at end of file 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
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