X-Git-Url: https://git.mdrn.pl/wolnelektury.git/blobdiff_plain/23f0993732ac597e0a4ab1330b62b970c09d476c..013ec8a416d4ff1ea3e1f2fa9ee2935623197ecd:/apps/libraries/models.py diff --git a/apps/libraries/models.py b/apps/libraries/models.py index c6db612b9..c83afbbba 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 _ @@ -5,28 +9,29 @@ from django.utils.translation import ugettext_lazy as _ class Catalog(models.Model): """Represents a dictionary of libraries""" - name = models.CharField(_('name'), max_length = 120, null = False) - slug = models.SlugField(_('slug'), max_length = 120, unique = True, db_index = True) + name = models.CharField(_('name'), max_length=120, null=False) + slug = models.SlugField(_('slug'), max_length=120, unique=True, db_index=True) class Meta: verbose_name = _('catalog') verbose_name_plural = _('catalogs') - + 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) - 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) + 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) class Meta: verbose_name = _('library') @@ -35,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])