Create course view

This commit is contained in:
Akash Bhave 2020-10-15 16:41:44 -04:00
parent 62b7273bab
commit 8d66e49cab
No known key found for this signature in database
GPG Key ID: 7293775E03FE1380
7 changed files with 33 additions and 9 deletions

View File

@ -1,8 +1,6 @@
from django.db import models from django.db import models
from django.core.validators import RegexValidator, FileExtensionValidator from django.core.validators import RegexValidator, FileExtensionValidator
# Create your models here.
class Subject(models.Model): class Subject(models.Model):
id = models.AutoField(primary_key=True) id = models.AutoField(primary_key=True)

View File

@ -5,5 +5,6 @@ from . import views
app_name = "courses" app_name = "courses"
urlpatterns = [ urlpatterns = [
path("<str:subject_name>/", views.subject_view) path("<str:subject_url>/", views.subject_view),
path("<str:subject_url>/<str:course_url>/", views.course_view),
] ]

View File

@ -6,7 +6,15 @@ from django.shortcuts import render, redirect, reverse, get_object_or_404
from .models import Subject, Course, Guide from .models import Subject, Course, Guide
def subject_view(request, subject_name): def subject_view(request, subject_url):
print(subject_name) subject = get_object_or_404(Subject, url=subject_url)
subject = get_object_or_404(Subject, url=subject_name) return render(request, "subject.html", {"subject": subject,
return render(request, "subject.html", {"subject": subject, "courses": subject.courses.all()}) "courses": subject.courses.all()})
def course_view(request, subject_url, course_url):
subject = get_object_or_404(Subject, url=subject_url)
course = get_object_or_404(Course, url=course_url)
return render(request, "course.html", {"subject": subject,
"course": course,
"guides": Guide.objects.filter(course=course)})

View File

@ -28,3 +28,11 @@ main {
.color-primary { .color-primary {
color: #568ea3; color: #568ea3;
} }
h1 {
opacity: 0.5;
transition: all 0.2s ease;
}
h1:hover {
opacity: 1;
}

View File

@ -0,0 +1,8 @@
{% extends "base.html" %} {% block main %}
<main>
<h2>{{subject.name}} / {{ course.name }}</h2>
{% for guide in guides %}
<p class="color-primary"><a href="{{guide.url}}"/>{{ guide.name }}</a></p>
{% endfor %}
</main>
{% endblock %}

View File

@ -1,5 +1,7 @@
{% extends "base.html" %} {% block main %} {% extends "base.html" %} {% block main %}
<main> <main>
<h1><a href="/">Subjects</a></h1>
{% for subject, courses in subjects %} {% for subject, courses in subjects %}
<h2>{{ subject.name }}</h2> <h2>{{ subject.name }}</h2>

View File

@ -1,9 +1,8 @@
{% extends "base.html" %} {% block main %} {% extends "base.html" %} {% block main %}
<main> <main>
<h2>{{ subject.name }}</h2>
{% for course in courses %} {% for course in courses %}
<p class="color-primary"><a href="/{{subject.url}}/{{course.url}}"/>{{ course.name }}</a></p> <p class="color-primary"><a href="/{{subject.url}}/{{course.url}}"/>{{ course.name }}</a></p>
{% endfor %} {% endfor %}
</main> </main>
{% endblock %} {% endblock %}