This repository is private.
All pages are served over SSL and all pushing and pulling is done over SSH.
No one may fork, clone, or view it unless they are added as a member.
Every repository with this icon (
) is private.
Every repository with this icon (
This repository is public.
Anyone may fork, clone, or view it.
Every repository with this icon (
) is public.
Every repository with this icon (
| name | age | message | |
|---|---|---|---|
| |
README.txt | Mon Sep 28 15:02:04 -0700 2009 | |
| |
django_urls/ | Wed Sep 10 16:28:31 -0700 2008 | |
| |
django_urls_demo/ | Wed Sep 10 16:42:29 -0700 2008 |
README.txt
Experimental replacement for Django's get_absolute_url method, as described on http://code.djangoproject.com/wiki/ReplacingGetAbsoluteUrl For the moment I've implemented it as a mixin class. Here's how you use it:: from django.db import models from django_urls.base import UrlMixin class ArticleWithPathDefined(models.Model, UrlMixin): slug = models.SlugField() def get_url_path(self): return '/articles/%s/' % self.slug class AssetWithUrlDefined(models.Model, UrlMixin): domain = models.CharField(max_length=30) filename = models.CharField(max_length = 30) def get_url(self): return 'http://%s/assets/%s' % (self.domain, self.filename) You need to define either get_url_path or get_url on a model - there's no need to define both. If you define one, the other will magically start working. Here's an example session using the above models:: >>> article = ArticleWithPathDefined.objects.create(slug = 'my-article') >>> article.get_url() 'http://localhost/articles/my-article/' >>> article.get_url_path() '/articles/my-article/' >>> asset = AssetWithUrlDefined.objects.create(domain='example.com', filename='logo.png') >>> asset.get_url() 'http://example.com/assets/logo.png' >>> asset.get_url_path() '/assets/logo.png'







