X-Git-Url: https://git.mdrn.pl/wolnelektury.git/blobdiff_plain/bc7619edc01175ed32c2155a19fba22ddb8365ce..e2b91b5e02b319565868635cf67799aabbda33fd:/apps/libraries/models.py?ds=sidebyside diff --git a/apps/libraries/models.py b/apps/libraries/models.py index d8a54a8a5..5f92421fc 100644 --- a/apps/libraries/models.py +++ b/apps/libraries/models.py @@ -1,13 +1,33 @@ from django.db import models 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) + + 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""" - #slug = models.SlugField(_('slug'), max_length=120, unique=True, db_index=True) - name = models.CharField(_('name'), max_length=120, blank=True) - 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') @@ -18,4 +38,4 @@ class Library(models.Model): @models.permalink def get_absolute_url(self): - return ('infopage', [self.slug]) + return ('libraries_library_view', [self.catalog.slug, self.slug]) \ No newline at end of file