BillLeeLee
[H]F Junkie
- Joined
- Jul 2, 2003
- Messages
- 13,486
Hopefully someone can help me see what I'm doing wrong here.
So I have a django model that contains this code:
And this template code that tests it:
However, the entry.get_absolute_url gets nothing. It's just an empty string.
Anyone see what I'm doing wrong?
Thanks in advance.
So I have a django model that contains this code:
Code:
from django.db import models
from django.db.models import permalink
from django.contrib.auth.models import User
from time import strftime
title = models.CharField(max_length=100)
entry_date = models.DateTimeField()
abstract = models.TextField(help_text='A short summary about this entry')
content = models.TextField(help_text='The main article goes here')
tags = models.ManyToManyField(Tag)
slug = models.SlugField(prepopulate_from=('title',),
help_text='Automagically built from the title',
unique_for_date='entry_date')
author = models.ForeignKey(User)
class Meta:
ordering = ('-entry_date',)
get_latest_by = 'entry_date'
class Admin:
list_display = ('entry_date', 'title', 'author')
list_filter = ('author', 'entry_date')
search_fields = ['title', 'summary', 'body']
def __unicode__(self):
return self.title
def get_absolute_url(self):
return ('django.views.generic.date_based.object_detail', None, {
'year': strftime('%Y', self.entry_date),
'month': strftime('%b', self.entry_date).lower(),
'day': strftime('%d', self.entry_date),
'slug': self.slug})
get_absolute_url = permalink(get_absolute_url)
And this template code that tests it:
Code:
{% extends "base.html" %}
{% block content %}
{% for entry in latest %}
<div class="post">
<div class="posthead"> <!-- begin class posthead -->
<div>{{ entry.get_absolute_url }}</div>
<div class="title"><!-- <a href="{{ entry.get_absolute_url }}">-->{{ entry.title }}<!-- </a>--></div>
<div><span class="entrydate">{{ entry.entry_date|date:"D M d Y G:i" }}</span></div>
<div class="byline">Posted by: <a href="mailto:{{ entry.author.email }}">{{ entry.author.first_name}} {{ entry.author.last_name }}</a></div>
</div> <!-- end div class posthead 1 -->
</div> <!-- end div post -->
<p>{{ entry.abstract|linebreaksbr }}</p>
{% endfor %}
{% endblock %}
However, the entry.get_absolute_url gets nothing. It's just an empty string.
Anyone see what I'm doing wrong?
Thanks in advance.