views:

72

answers:

1

I'm currently reading Practical Django Projects and in the Django admin interface there is an option to "View on site" when entering information.

But after finishing chapter 5 of the book I started to tinker with the admin interface and found that clicking this link with my categories app doesn't work as it isn't appending weblog to the URL, so they appear like this:

http://127.0.0.1:8000/categories/test-cat

when they should be like this...

http://127.0.0.1:8000/weblog/categories/test-cat

However on my entries model they work perfectly well. So I tried to see what was right in the in the Entries application to find out what was incorrect on the Categories application.

I'm been looking for about 2 hours and I can't identify where Django does this. I have even copied the source code from online although some of it appears to be missing.

My get_absolute_url() is as follows:

def get_absolute_url(self):
    return "/categories/%s/" % self.slug

I edited to:

def get_absolute_url(self):
    return "/weblog/categories/%s/" % self.slug

and it resolves the issue.

My question now is, why does the Entries application not require this but the Categories application does?

My code from class Entry:

def get_absolute_url(self):
    return ('coltrane_entry_detail', (), { 'year': self.pub_date.strftime("%Y"),
                                        'month': self.pub_date.strftime("%b").lower(),
                                       'day': self.pub_date.strftime("%d"),
                                       'slug': self.slug })
get_absolute_url = models.permalink(get_absolute_url)
+1  A: 

It uses the get_absolute_url() method on the model. Change that and it should work :)

[edit] For the edited question. In your category model you are using a hardcoded link while you are using a permalink at the entries model. I suggest you use permalinks at both locations to solve the problem.

Here's the documentation on how to use it: http://docs.djangoproject.com/en/dev/ref/models/instances/#the-permalink-decorator

WoLpH