Use reverse URL generation for detail view

This commit is contained in:
Ben Sturmfels 2023-10-05 22:07:34 +11:00
parent 293350658a
commit 7fa679f795
Signed by: bsturmfels
GPG key ID: 023C05E2C9C068F0
2 changed files with 12 additions and 5 deletions

View file

@ -18,6 +18,7 @@
#
from django.db import models
from django.conf import settings
from django.urls import reverse
#from podjango.apps.staff.models import Person
from datetime import datetime, timedelta
@ -34,7 +35,7 @@ class CastTag(models.Model):
return self.label
def get_absolute_url(self):
return "/cast/?tag=%s" % self.slug
return reverse('podjango:cast') + "?tag=%s" % self.slug
class Cast(models.Model):
"""Cast"""
@ -66,10 +67,15 @@ class Cast(models.Model):
return self.title
def get_absolute_url(self):
return "/cast/%s/%s/" % (self.pub_date.strftime("%Y/%b/%d").lower(),
self.slug)
# FIXME
# return (u"/cast/%s/" % (self.slug))
return reverse(
'podjango:detail',
kwargs={
'year': self.pub_date.year,
'month': self.pub_date.strftime("%b").lower(),
'day': self.pub_date.day,
'slug': self.slug,
}
)
def is_recent(self):
return self.pub_date > (datetime.now() - timedelta(days=14))

View file

@ -17,6 +17,7 @@
# "AGPLv3". If not, see <http://www.gnu.org/licenses/>.
#
from datetime import datetime
from functools import reduce
from django.views.generic.list import ListView
from django.shortcuts import get_object_or_404, render