Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Description on tag pages #443

Merged
merged 7 commits into from
Jun 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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