X-Git-Url: https://git.mdrn.pl/wolnelektury.git/blobdiff_plain/ab9decfcead37a9b1c07cb9627e61e094eaf111d..99f6dd4f1ff0390de9a9bbd4e3352b953cb9a235:/apps/libraries/models.py?ds=sidebyside diff --git a/apps/libraries/models.py b/apps/libraries/models.py index db6c6a5c5..96473eb03 100644 --- a/apps/libraries/models.py +++ b/apps/libraries/models.py @@ -1,3 +1,7 @@ +# -*- coding: utf-8 -*- +# This file is part of Wolnelektury, licensed under GNU Affero GPLv3 or later. +# Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information. +# from django.db import models from django.utils.translation import ugettext_lazy as _ @@ -15,11 +19,16 @@ class Catalog(models.Model): def __unicode__(self): return self.name - + @models.permalink + def get_absolute_url(self): + return ('libraries_catalog_view', [self.slug]) + + class Library(models.Model): """Represent a single library in the libraries dictionary""" name = models.CharField(_('name'), max_length = 120, blank = True) + slug = models.SlugField(_('slug'), max_length = 120, unique = True, db_index = True, null = True) catalog = models.ForeignKey(Catalog, null = False, related_name = 'libraries', on_delete = models.PROTECT) url = models.CharField(_('url'), max_length = 120, blank = True) description = models.TextField(_('description'), blank = True) @@ -31,3 +40,6 @@ class Library(models.Model): def __unicode__(self): return self.name + @models.permalink + def get_absolute_url(self): + return ('libraries_library_view', [self.catalog.slug, self.slug])