coding utf-8 from pytils translit import slugify from django db import

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# -*- coding: utf-8
from pytils.translit import slugify
from django.db import models
from django.core.urlresolvers import reverse
from stdimage.fields import StdImageField
from project.models import Item
class Gallery(models.Model):
title = models.CharField(max_length=100)
slug = models.SlugField(max_length=100, editable=False)
event = models.ForeignKey(Item)
date = models.DateField()
show_url = lambda self: reverse("show-gallery", args=[self.slug])
def save(self, *args, **kwargs):
self.slug = slugify(self.title)
super(Gallery, self).save(*args, **kwargs)
def __unicode__(self):
return self.title
class Meta:
verbose_name = u"Галерея"
verbose_name_plural = u"Галереи"
class Photo(models.Model):
gallery = models.ForeignKey(Gallery)
image = StdImageField(upload_to="uploads", thumbnails=[('thumbnail', 152, 119, True)])
def __unicode__(self):
return "%s #%s" % (self.gallery.title, self.id)
class Meta:
verbose_name = u"Фотография"
verbose_name_plural = u"Фотографии"