Cloudcms Service model
[snf-cloudcms] / cloudcms / models.py
index 696b268..a4248b5 100644 (file)
@@ -36,9 +36,11 @@ import datetime
 from django.db import models
 from django.conf import settings
 from django.contrib.sites import models as sites_models
+from django.utils.translation import ugettext_lazy as _, ugettext, ungettext
 from django.core.cache import cache
 from django.utils import simplejson
 
+from feincms import translations
 from feincms.module.medialibrary.fields import MediaFileForeignKey
 from feincms.module.medialibrary.models import MediaFile
 
@@ -143,3 +145,45 @@ class ClientVersionSource(models.Model):
 # hook for feincms configuration, is this appropriate place ??? who knows
 from cloudcms.cms import *
 
+class Service(models.Model, translations.TranslatedObjectMixin):
+    """
+    Service.
+    """
+
+    ordering = models.SmallIntegerField(_('ordering'), default=0)
+
+    class Meta:
+        verbose_name = _('service')
+        verbose_name_plural = _('services')
+        ordering = ['-ordering',]
+
+    objects = translations.TranslatedObjectManager()
+
+    def __unicode__(self):
+        trans = translations.TranslatedObjectMixin.__unicode__(self)
+        return trans or _('Unnamed category')
+
+
+class ServiceTranslation(translations.Translation(Service)):
+    """
+    Service translation
+    """
+    title = models.CharField(_('service title'), max_length=100)
+    slug = models.SlugField(_('slug'), unique=True)
+    description = models.CharField(_('description'), max_length=250, blank=True)
+    cms_page = models.ForeignKey(Page, null=True, blank=True)
+
+    class Meta:
+        verbose_name = _('service translation')
+        verbose_name_plural = _('service translations')
+        ordering = ['title']
+
+    def __unicode__(self):
+        return self.title
+
+    def save(self, *args, **kwargs):
+        if not self.slug:
+            self.slug = slugify(self.title)
+
+        super(ServiceTranslation, self).save(*args, **kwargs)
+