diff --git a/entries/kinds.py b/entries/kinds.py index c4e37a7..5703f54 100644 --- a/entries/kinds.py +++ b/entries/kinds.py @@ -13,10 +13,6 @@ class Entry: def entry(self): return self.plural + '_entry' - @property - def entry_slug(self): - return self.entry + '_slug' - Note = Entry( id='note', diff --git a/entries/models.py b/entries/models.py index 7e25985..821d353 100644 --- a/entries/models.py +++ b/entries/models.py @@ -88,12 +88,10 @@ class Entry(ModelMeta, models.Model): @property def url(self): kind = kinds.from_id[self.kind] - route = kind.entry args = [self.id] if kind.slug: - route = kind.entry_slug args.append(self.slug) - return reverse('entries:' + route, args=args) + return reverse('entries:' + kind.entry, args=args) @property def slug(self): diff --git a/entries/urls.py b/entries/urls.py index a9b04ba..84d38e4 100644 --- a/entries/urls.py +++ b/entries/urls.py @@ -3,8 +3,8 @@ from . import kinds, views from lemoncurry import breadcrumbs as crumbs -def to_url(*args): - return '^{0}$'.format('/'.join(args)) +def to_pat(*args): + return '^{0}$'.format(''.join(args)) def prefix(route): @@ -15,14 +15,12 @@ app_name = 'entries' urlpatterns = [] for k in kinds.all: kind = k.plural - id = r'(?P\d+)' - slug = r'(?P.+)' + id = r'/(?P\d+)' + slug = r'(?:/(?P.+))?' urlpatterns += ( - url(to_url(kind), views.index, name=k.index, kwargs={'kind': k}), - url(to_url(kind, id), views.entry, name=k.entry), - url(to_url(kind, id, slug), views.entry, name=k.entry_slug), + url(to_pat(kind), views.index, name=k.index, kwargs={'kind': k}), + url(to_pat(kind, id, slug), views.entry, name=k.entry), ) crumbs.add(prefix(k.index), label=k.plural, parent='home:index') crumbs.add(prefix(k.entry), parent=prefix(k.index)) - crumbs.add(prefix(k.entry_slug), parent=prefix(k.index))