aboutsummaryrefslogtreecommitdiffstats
path: root/pydis_site/apps/content/models
diff options
context:
space:
mode:
authorGravatar Hassan Abouelela <[email protected]>2022-08-14 04:44:57 +0200
committerGravatar Hassan Abouelela <[email protected]>2022-08-14 05:36:12 +0200
commitb4911d03faf8eecf5c4cced6f8036b0b2ef01d58 (patch)
treecc32c183b6894829dea32506eaf77e25ffa7e73f /pydis_site/apps/content/models
parentImprove Tag Cropping (diff)
Move Tag URL To Property And Add Group
The URLs can be simply constructed using the other tag properties, so they were removed from the database in favor of a property. A group field was also added to support tags within groups. Signed-off-by: Hassan Abouelela <[email protected]>
Diffstat (limited to 'pydis_site/apps/content/models')
-rw-r--r--pydis_site/apps/content/models/tag.py17
1 files changed, 16 insertions, 1 deletions
diff --git a/pydis_site/apps/content/models/tag.py b/pydis_site/apps/content/models/tag.py
index 1437b96a..01264ff1 100644
--- a/pydis_site/apps/content/models/tag.py
+++ b/pydis_site/apps/content/models/tag.py
@@ -4,6 +4,8 @@ from django.db import models
class Tag(models.Model):
"""A tag from the python-discord server."""
+ URL_BASE = "https://github.com/python-discord/bot/tree/main/bot/resources/tags"
+
last_updated = models.DateTimeField(
help_text="The date and time this data was last fetched.",
auto_now=True,
@@ -13,5 +15,18 @@ class Tag(models.Model):
primary_key=True,
max_length=50,
)
+ group = models.CharField(
+ help_text="The group the tag belongs to.",
+ null=True,
+ max_length=50,
+ )
body = models.TextField(help_text="The content of the tag.")
- url = models.URLField(help_text="The URL to this tag on GitHub.")
+
+ @property
+ def url(self) -> str:
+ """Get the URL of the tag on GitHub."""
+ url = Tag.URL_BASE
+ if self.group:
+ url += f"/{self.group}"
+ url += f"/{self.name}.md"
+ return url