| 129 | And you use it like this: |
| 130 | {{{ |
| 131 | #!python |
| 132 | from django.db import models |
| 133 | from django_urls.base import UrlMixin |
| 134 | |
| 135 | class ArticleWithPathDefined(models.Model, UrlMixin): |
| 136 | slug = models.SlugField() |
| 137 | |
| 138 | def get_url_path(self): |
| 139 | return '/articles/%s/' % self.slug |
| 140 | |
| 141 | class AssetWithUrlDefined(models.Model, UrlMixin): |
| 142 | domain = models.CharField(max_length=30) |
| 143 | filename = models.CharField(max_length = 30) |
| 144 | |
| 145 | def get_url(self): |
| 146 | return 'http://%s/assets/%s' % (self.domain, self.filename) |
| 147 | }}} |