1 # -*- coding: utf-8 -*-
\r
2 # This file is part of Wolnelektury, licensed under GNU Affero GPLv3 or later.
\r
3 # Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information.
\r
5 from django.db import models
\r
6 from django.utils.translation import ugettext_lazy as _
\r
9 class Catalog(models.Model):
\r
10 """Represents a dictionary of libraries"""
\r
12 name = models.CharField(_('name'), max_length=120, null=False)
\r
13 slug = models.SlugField(_('slug'), max_length=120, unique=True, db_index=True)
\r
16 verbose_name = _('catalog')
\r
17 verbose_name_plural = _('catalogs')
\r
23 def get_absolute_url(self):
\r
24 return 'libraries_catalog_view', [self.slug]
\r
27 class Library(models.Model):
\r
28 """Represent a single library in the libraries dictionary"""
\r
30 name = models.CharField(_('name'), max_length=120, blank=True)
\r
31 slug = models.SlugField(_('slug'), max_length=120, unique=True, db_index=True, null=True)
\r
32 catalog = models.ForeignKey(Catalog, null=False, related_name='libraries', on_delete=models.PROTECT)
\r
33 url = models.CharField(_('url'), max_length=120, blank=True)
\r
34 description = models.TextField(_('description'), blank=True)
\r
37 verbose_name = _('library')
\r
38 verbose_name_plural = _('libraries')
\r
44 def get_absolute_url(self):
\r
45 return ('libraries_library_view', [self.catalog.slug, self.slug])
\r