X-Git-Url: https://git.mdrn.pl/wolnelektury.git/blobdiff_plain/357027375ff8867f42ca34bcbfb5a78b5b185fc3..5221177061d377830cdee4079e57b777b53cb8a7:/src/picture/models.py?ds=sidebyside diff --git a/src/picture/models.py b/src/picture/models.py index 5aabe3c89..bffb63912 100644 --- a/src/picture/models.py +++ b/src/picture/models.py @@ -17,6 +17,7 @@ from StringIO import StringIO import jsonfield import itertools import logging +import re from PIL import Image @@ -123,10 +124,31 @@ class Picture(models.Model): def __unicode__(self): return self.title + def author_str(self): + return ", ".join(str(t) for t in self.tags.filter(category='author')) + @permalink def get_absolute_url(self): return ('picture.views.picture_detail', [self.slug]) + def get_initial(self): + try: + return re.search(r'\w', self.title, re.U).group(0) + except AttributeError: + return '' + + def get_next(self): + try: + return type(self).objects.filter(sort_key__gt=self.sort_key)[0] + except IndexError: + return None + + def get_previous(self): + try: + return type(self).objects.filter(sort_key__lt=self.sort_key).order_by('-sort_key')[0] + except IndexError: + return None + @classmethod def from_xml_file(cls, xml_file, image_file=None, image_store=None, overwrite=False): """