mirror of
https://github.com/tjsga/studyguides.git
synced 2025-04-05 03:40:16 -04:00
display tags
This commit is contained in:
parent
7eee29008b
commit
b1aea97fc3
|
@ -0,0 +1,23 @@
|
|||
# Generated by Django 3.0.6 on 2020-10-27 12:27
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('courses', '0005_auto_20201020_1737'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='guide',
|
||||
name='tags',
|
||||
field=models.ManyToManyField(to='courses.Tag'),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='subject',
|
||||
name='courses',
|
||||
field=models.ManyToManyField(related_name='subject', to='courses.Course'),
|
||||
),
|
||||
]
|
|
@ -0,0 +1,18 @@
|
|||
# Generated by Django 3.0.6 on 2020-10-27 12:50
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('courses', '0006_auto_20201027_1227'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='guide',
|
||||
name='tags',
|
||||
field=models.ManyToManyField(related_name='guide', to='courses.Tag'),
|
||||
),
|
||||
]
|
|
@ -8,7 +8,7 @@ class Subject(models.Model):
|
|||
url = models.CharField("URL", max_length=20, unique=True, validators=[RegexValidator(
|
||||
regex="^[a-zA-Z0-9_\-]+$", message="Only alphanumeric, dashes, and underscores allowed")])
|
||||
|
||||
courses = models.ManyToManyField("Course", related_name="subject", null=True, blank=True)
|
||||
courses = models.ManyToManyField("Course", related_name="subject")
|
||||
|
||||
def __str__(self):
|
||||
return self.name
|
||||
|
@ -28,7 +28,7 @@ class Guide(models.Model):
|
|||
id = models.AutoField(primary_key=True)
|
||||
name = models.CharField(max_length=100)
|
||||
|
||||
tags = models.ManyToManyField("Tag", null=True)
|
||||
tags = models.ManyToManyField("Tag", related_name="guide")
|
||||
course = models.ForeignKey(Course, on_delete=models.CASCADE, null=True)
|
||||
url = models.URLField(max_length=300)
|
||||
|
||||
|
|
|
@ -6,5 +6,6 @@ app_name = "courses"
|
|||
|
||||
urlpatterns = [
|
||||
path("<str:subject_url>/", views.subject_view),
|
||||
path("tag/<str:tag>/", views.tag_view, name="tag"),
|
||||
path("<str:subject_url>/<str:course_url>/", views.course_view),
|
||||
]
|
||||
|
|
|
@ -3,7 +3,7 @@ import random
|
|||
from django import http
|
||||
from django.shortcuts import render, redirect, reverse, get_object_or_404
|
||||
|
||||
from .models import Subject, Course, Guide
|
||||
from .models import Subject, Course, Guide, Tag
|
||||
|
||||
|
||||
def subject_view(request, subject_url):
|
||||
|
@ -17,4 +17,8 @@ def course_view(request, subject_url, course_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)})
|
||||
"guides": [[g, g.tags.all()] for g in Guide.objects.filter(course=course)]})
|
||||
|
||||
def tag_view(request, tag):
|
||||
tag = get_object_or_404(Tag, name=tag)
|
||||
return render(request, "tag.html", {"tag": tag, "guides": [[g, g.tags.all()] for g in tag.guide.all()]})
|
|
@ -1,8 +1,8 @@
|
|||
{% extends "base.html" %} {% load static %} {% block main %}
|
||||
<main>
|
||||
<h1><a href="/">All</a> / <a href="/{{subject.url}}">{{subject.name}}</a> / <a href="/{{subject.url}}/{{course.url}}">{{course.name}}</a></h1>
|
||||
{% for guide in guides %}
|
||||
<p class="item"><a href="{{guide.url}}" target="_blank"/>{% if guide.teacher %}<span class="teacher">[{{guide.teacher}}] </span>{% endif %}{{ guide.name }}</a></p>
|
||||
{% for guide, tags in guides %}
|
||||
<p class="item"><b><a href="{{guide.url}}">{{ guide.name }}</a></b> {% for t in tags %}<a href='{% url "courses:tag" t.name %}'>{{ t }} </a>{% endfor %}</p>
|
||||
{% endfor %}
|
||||
</main>
|
||||
{% endblock %}
|
||||
|
|
14
studyguides/templates/tag.html
Normal file
14
studyguides/templates/tag.html
Normal file
|
@ -0,0 +1,14 @@
|
|||
{% extends "base.html" %}
|
||||
|
||||
{% load static %}
|
||||
|
||||
{% block main %}
|
||||
<main>
|
||||
<h1><a href="/">All</a> / {{ tag }}</h1>
|
||||
{% for guide, tags in guides %}
|
||||
<p class="item">
|
||||
<b><a href="{{ guide.url }}">{{ guide.name }}</a></b> {% for t in tags %}<a href='{% url "courses:tag" t.name %}'>{{ t }} </a>{% endfor %}
|
||||
</p>
|
||||
{% endfor %}
|
||||
</main>
|
||||
{% endblock %}
|
Loading…
Reference in New Issue
Block a user