X-Git-Url: https://git.mdrn.pl/wolnelektury.git/blobdiff_plain/357027375ff8867f42ca34bcbfb5a78b5b185fc3..084f20588e607aa9ae3ed280b6a2f0349b6a3200:/src/catalogue/models/fragment.py diff --git a/src/catalogue/models/fragment.py b/src/catalogue/models/fragment.py index a3dbdea54..ef15f85b4 100644 --- a/src/catalogue/models/fragment.py +++ b/src/catalogue/models/fragment.py @@ -1,10 +1,9 @@ -# -*- 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.conf import settings from django.contrib.contenttypes.fields import GenericRelation -from django.core.urlresolvers import reverse +from django.urls import reverse from django.db import models from django.utils.translation import ugettext_lazy as _ from newtagging import managers @@ -17,7 +16,7 @@ class Fragment(models.Model): text = models.TextField() short_text = models.TextField(editable=False) anchor = models.CharField(max_length=120) - book = models.ForeignKey('Book', related_name='fragments') + book = models.ForeignKey('Book', models.CASCADE, related_name='fragments') objects = models.Manager() tagged = managers.ModelTaggedItemManager(Tag) @@ -35,10 +34,17 @@ class Fragment(models.Model): def get_absolute_url(self): return '%s#m%s' % (reverse('book_text', args=[self.book.slug]), self.anchor) + def get_api_url(self): + return reverse('catalogue_api_fragment', args=[self.book.slug, self.anchor]) + def get_short_text(self): """Returns short version of the fragment.""" return self.short_text if self.short_text else self.text + @property + def themes(self): + return self.tags.filter(category='theme') + def flush_includes(self, languages=True): if not languages: return