Source

gnocchi-gallery / gnocchi / gallery / models.py

Full commit
from django.db import models
import os

from gnocchi.tools.attr import AttrHelper
from taggit.managers import TaggableManager
from django.contrib.contenttypes import generic

class Gallery(models.Model):
    name = models.CharField(max_length=128)
    slug = models.SlugField()

    class Meta:
        verbose_name_plural = 'Galleries'
    def __unicode__(self):
        return self.name

def upload_to(instance, filename):
    return os.path.join('gallery', instance.gallery.slug, filename)

class Image(models.Model, AttrHelper):
    image = models.ImageField(upload_to=upload_to)
    gallery = models.ForeignKey(Gallery, related_name='images')
    name = models.CharField(max_length=128, blank=True)
    order = models.IntegerField(default=0)

    attributes = generic.GenericRelation('tools.Attribute')
    tags = TaggableManager(blank=True)

    class Meta:
        ordering = ('order', 'id',)
        verbose_name_plural = 'Gallery Images'

class ThumbnailConfig(models.Model, AttrHelper):
    name = models.CharField(max_length=128)

    attributes = generic.GenericRelation('tools.Attribute')