Create subject view, update styling

This commit is contained in:
Akash Bhave 2020-10-15 16:24:45 -04:00
parent 6105a077b7
commit 62b7273bab
No known key found for this signature in database
GPG Key ID: 7293775E03FE1380
6 changed files with 22 additions and 9 deletions

View File

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

View File

@ -4,5 +4,9 @@ from django import http
from django.shortcuts import render, redirect, reverse, get_object_or_404
from .models import Subject, Course, Guide
# Create your views here.
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()})

View File

@ -25,6 +25,6 @@ main {
margin: 30px;
}
.subject {
.color-primary {
color: #568ea3;
}

View File

@ -4,7 +4,7 @@
<h2>{{ subject.name }}</h2>
{% for course in courses %}
<p class="subject"><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>

View File

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

View File

@ -21,12 +21,12 @@ from django.conf.urls.static import static
urlpatterns = [
path('admin/', admin.site.urls),
path('courses/', include('studyguides.apps.courses.urls', namespace = 'courses')),
path('auth/', include('studyguides.apps.auth.urls', namespace = 'auth')),
path('auth/', include('studyguides.apps.auth.urls', namespace='auth')),
path('', include('studyguides.apps.courses.urls', namespace='courses')),
path('', include('studyguides.apps.home.urls', namespace='home')),
path('', include('social_django.urls', namespace = 'social')),
path('', include('social_django.urls', namespace='social')),
]
if settings.DEBUG:
urlpatterns.extend(static("static/", document_root=settings.STATIC_ROOT))
urlpatterns.extend(static("media/", document_root = settings.MEDIA_ROOT))
urlpatterns.extend(static("media/", document_root=settings.MEDIA_ROOT))