Commit 653eb15b authored by Ciella's avatar Ciella

Bugfix for models, URLs, and views

parent 385eee3d
from django.db import models from django.db import models
from django.urls import reverse
# Create your models here. # Create your models here.
class Course(models.Model): class Course(models.Model):
...@@ -7,7 +8,7 @@ class Course(models.Model): ...@@ -7,7 +8,7 @@ class Course(models.Model):
section = models.CharField(max_length=3) section = models.CharField(max_length=3)
def __str__(self): def __str__(self):
return '{} {}'.format(self.code, self.section) return '{} {} - {}'.format(self.code, self.title, self.section)
class Assignment(models.Model): class Assignment(models.Model):
...@@ -22,4 +23,7 @@ class Assignment(models.Model): ...@@ -22,4 +23,7 @@ class Assignment(models.Model):
super(Assignment, self).save(*args, **kwargs) super(Assignment, self).save(*args, **kwargs)
def __str__(self): def __str__(self):
return '{} {}: {}'.format(self.course.code, self.course.section, self.name) return '{}'.format(self.name)
\ No newline at end of file
def get_absolute_url(self):
return reverse('assignments:assignment-details', kwargs={'pk': self.pk})
\ No newline at end of file
...@@ -3,10 +3,10 @@ from django.urls import path ...@@ -3,10 +3,10 @@ from django.urls import path
from .views import assignments_view, AssignmentDetailView, AssignmentCreateView, AssignmentUpdateView from .views import assignments_view, AssignmentDetailView, AssignmentCreateView, AssignmentUpdateView
urlpatterns = [ urlpatterns = [
path('assignments/', assignments_view, name='assignments_view'), path('', assignments_view, name='assignments'),
path('assignments/<int:pk>/details/', AssignmentDetailView.as_view(), name='assignment-details'), path('<int:pk>/details/', AssignmentDetailView.as_view(), name='assignment-details'),
path('assignments/add/', AssignmentCreateView.as_view(), name='assignment-add'), path('add/', AssignmentCreateView.as_view(), name='assignment-add'),
path('assignments/<int:pk>/edit/', AssignmentUpdateView.as_view(), name='assignment-edit'), path('<int:pk>/edit/', AssignmentUpdateView.as_view(), name='assignment-edit'),
] ]
app_name = 'assignments' app_name = 'assignments'
\ No newline at end of file
...@@ -8,7 +8,7 @@ from .models import Assignment ...@@ -8,7 +8,7 @@ from .models import Assignment
def assignments_view(request): def assignments_view(request):
tasks = Assignment.objects.all() tasks = Assignment.objects.all()
context = {'tasks' : tasks} context = {'tasks' : tasks}
return render(request, 'assignments/assignments.html') return render(request, 'assignments/assignments.html', context)
class AssignmentDetailView(DetailView): class AssignmentDetailView(DetailView):
......
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