1 # This file is part of Wolnelektury, licensed under GNU Affero GPLv3 or later.
\r
2 # Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information.
\r
4 from django.db import models
\r
5 from django.urls import reverse
\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
22 def get_absolute_url(self):
\r
23 return reverse('libraries_catalog_view', args=[self.slug])
\r
26 class Library(models.Model):
\r
27 """Represent a single library in the libraries dictionary"""
\r
29 name = models.CharField(_('name'), max_length=120, blank=True)
\r
30 slug = models.SlugField(_('slug'), max_length=120, unique=True, db_index=True, null=True)
\r
31 catalog = models.ForeignKey(Catalog, null=False, related_name='libraries', on_delete=models.PROTECT)
\r
32 url = models.CharField(_('url'), max_length=120, blank=True)
\r
33 description = models.TextField(_('description'), blank=True)
\r
36 verbose_name = _('library')
\r
37 verbose_name_plural = _('libraries')
\r
42 def get_absolute_url(self):
\r
43 return reverse('libraries_library_view', args=[self.catalog.slug, self.slug])
\r