From fabbe3385841576b6b9116c1db609d9c9174f8ba Mon Sep 17 00:00:00 2001 From: =?utf8?q?Fr=C3=A9d=C3=A9ric=20Perrin?= Date: Tue, 1 Nov 2016 00:31:40 +0000 Subject: [PATCH] Implement and use get_absolute_url --- quotes/models.py | 15 ++++++++++++++- quotes/templates/quotes/display.html | 8 ++++---- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/quotes/models.py b/quotes/models.py index e23fde5..83bf62b 100644 --- a/quotes/models.py +++ b/quotes/models.py @@ -1,4 +1,6 @@ from django.db import models +from django.urls import reverse + from localmodels import HTMLField # Create your models here. @@ -13,7 +15,9 @@ class BaseTag(models.Model): class AuthorTag(BaseTag): pass class WorkTag(BaseTag): pass -class QuoteTag(BaseTag): pass +class QuoteTag(BaseTag): + def get_absolute_url(self): + return reverse('quotes:tags', args=[str(self.id)]) class CommonData(models.Model): creation_date = models.DateTimeField(auto_now_add=True) @@ -46,6 +50,9 @@ class Author(CommonData): def __str__(self): return self.name + def get_absolute_url(self): + return reverse('quotes:author', args=[str(self.id)]) + # class DatePrecision(models.CharField): # DAY = "D" # MONTH = "M" @@ -79,6 +86,9 @@ class Work(CommonData): def __str__(self): return "%s: %s (%s)" % (self.author.name, self.name, self.date) + def get_absolute_url(self): + return reverse('quotes:work', args=[str(self.id)]) + class Quote(CommonData): text = HTMLField() tags = models.ManyToManyField(QuoteTag, blank=True) @@ -86,3 +96,6 @@ class Quote(CommonData): def __str__(self): return self.work.author.name + ": " + self.text + + def get_absolute_url(self): + return reverse('quotes:onequote', args=[str(self.id)]) diff --git a/quotes/templates/quotes/display.html b/quotes/templates/quotes/display.html index 696f754..d15cc05 100644 --- a/quotes/templates/quotes/display.html +++ b/quotes/templates/quotes/display.html @@ -14,9 +14,9 @@ Hide details

— - {{ quote.work.author.name }}, - {{ quote.work.name }}

@@ -33,7 +33,7 @@

Tags: {% for tag in quote.tags.all %} - {{ tag.tag }}{% if not forloop.last %}, {% endif %} {% endfor %} @@ -43,6 +43,6 @@

-- 2.43.0