Thursday, September 13, 2012

get_absolute_url is returning '' instead of url

Hi,

I'm getting blank get_absolute_url problems that I just can't solve. I
can get to an object by actually visiting the url that would be
constructed - I've checked that: app/session/year/month/day/slug

models.py:
class Session(models.Model):
...
@models.permalink
def get_absolute_url(self):
return ('session_view', (), {
'year': self.date.year,
'month': self.date.month,
'day': self.date.day,
'slug': self.slug})

As you can see from the template snippet below, I'm printing out all
that makes up the url, and am getting correct results, except for
get_absolute_url

template:
{% for x in session %}
<a href="{{ x.get_absolute_url }}">{{
x.subject.name }}</a> {{ x.date.year }} {{ x.date.month }} {{
x.date.day}} {{ x.slug }}<br />

I'm importing the session_view
urls.py:

from tafe.views import session_create, session_view, timetable_daily_view
...
url(r'^session/(?P<year>\d{4})/(?P<month>\d{1,2})/(?P<day>\d{1,2})/(?P<slug>[-\w]+)/$',
session_view),

And the view seems to be properly constructed - I've got debug on, and
I'm getting the page I expected rendering. It's only the
get_absolute_url that's coming back blank.

views.py
@login_required
def session_view(request, year, month, day, slug):
req_date = datetime.date(int(year), int(month), int(day))
session = get_object_or_404(Session, slug=slug, date=req_date)

return render_to_response('tafe/session_detail.html',{'session':session})


I've even checked that the objects have the slugs as per expected in
the admin interface (although visiting the address that the g_a_u
should be returning works, so that was already a given.)

Any ideas? Any tips on where to start looking?

cheers
L.

--
...we look at the present day through a rear-view mirror. This is
something Marshall McLuhan said back in the Sixties, when the world
was in the grip of authentic-seeming future narratives. He said, "We
look at the present through a rear-view mirror. We march backwards
into the future."

http://www.warrenellis.com/?p=14314

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate