Skip to content

Commit

Permalink
Description on tag pages (#443)
Browse files Browse the repository at this point in the history
  • Loading branch information
simonw authored Jun 18, 2024
1 parent 709be0e commit 6354c20
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 0 deletions.
18 changes: 18 additions & 0 deletions blog/migrations/0020_tag_description.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django A.B on YYYY-MM-DD HH:MM

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
("blog", "0019_blogmark_use_markdown"),
]

operations = [
migrations.AddField(
model_name="tag",
name="description",
field=models.TextField(blank=True),
),
]
7 changes: 7 additions & 0 deletions blog/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,17 @@

class Tag(models.Model):
tag = models.SlugField(unique=True)
description = models.TextField(blank=True) # Added description field

def __str__(self):
return self.tag

def description_rendered(self):
if self.description:
return mark_safe(markdown(self.description))
else:
return ''

def get_absolute_url(self):
return "/tags/%s/" % self.tag

Expand Down
4 changes: 4 additions & 0 deletions static/css/all.css
Original file line number Diff line number Diff line change
Expand Up @@ -1144,3 +1144,7 @@ div.ea-placement a:link {
margin-left: 1em;
margin-bottom: 0.1em;
}

.tag-description {
margin-bottom: 1em;
}
4 changes: 4 additions & 0 deletions templates/archive_tag.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@

{% block primary %}
<h2 class="archive-tag-h2">{{ total }} item{{ total|pluralize }} tagged “{{ tags|join:"” and “" }}”</h2>
<!-- Tag ID: {{ tag.pk }} -->
{% if tag.description %}
<div class="tag-description">{{ tag.description_rendered }}</div>
{% endif %}

{% if total > 10 %}
<form action="/search/" method="GET">
Expand Down

0 comments on commit 6354c20

Please sign in to comment.