mirror of
https://github.com/tjsga/studyguides.git
synced 2025-04-05 03:40:16 -04:00
Create course view
This commit is contained in:
parent
62b7273bab
commit
8d66e49cab
|
@ -1,8 +1,6 @@
|
|||
from django.db import models
|
||||
from django.core.validators import RegexValidator, FileExtensionValidator
|
||||
|
||||
# Create your models here.
|
||||
|
||||
|
||||
class Subject(models.Model):
|
||||
id = models.AutoField(primary_key=True)
|
||||
|
|
|
@ -5,5 +5,6 @@ from . import views
|
|||
app_name = "courses"
|
||||
|
||||
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),
|
||||
]
|
||||
|
|
|
@ -6,7 +6,15 @@ from django.shortcuts import render, redirect, reverse, get_object_or_404
|
|||
from .models import Subject, Course, Guide
|
||||
|
||||
|
||||
def subject_view(request, subject_name):
|
||||
print(subject_name)
|
||||
subject = get_object_or_404(Subject, url=subject_name)
|
||||
return render(request, "subject.html", {"subject": subject, "courses": subject.courses.all()})
|
||||
def subject_view(request, subject_url):
|
||||
subject = get_object_or_404(Subject, url=subject_url)
|
||||
return render(request, "subject.html", {"subject": subject,
|
||||
"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)})
|
||||
|
|
|
@ -28,3 +28,11 @@ main {
|
|||
.color-primary {
|
||||
color: #568ea3;
|
||||
}
|
||||
|
||||
h1 {
|
||||
opacity: 0.5;
|
||||
transition: all 0.2s ease;
|
||||
}
|
||||
h1:hover {
|
||||
opacity: 1;
|
||||
}
|
||||
|
|
|
@ -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 %}
|
|
@ -1,5 +1,7 @@
|
|||
{% extends "base.html" %} {% block main %}
|
||||
<main>
|
||||
<h1><a href="/">Subjects</a></h1>
|
||||
|
||||
{% for subject, courses in subjects %}
|
||||
<h2>{{ subject.name }}</h2>
|
||||
|
||||
|
|
|
@ -1,9 +1,8 @@
|
|||
{% extends "base.html" %} {% block main %}
|
||||
<main>
|
||||
<h2>{{ subject.name }}</h2>
|
||||
{% for course in courses %}
|
||||
|
||||
<p class="color-primary"><a href="/{{subject.url}}/{{course.url}}"/>{{ course.name }}</a></p>
|
||||
|
||||
{% endfor %}
|
||||
</main>
|
||||
{% endblock %}
|
||||
|
|
Loading…
Reference in New Issue
Block a user