class BlogCategory(TranslatableModel): """ Blog category """ parent = models.ForeignKey('self', verbose_name=_('parent'), null=True, blank=True) date_created = models.DateTimeField(_('created at'), auto_now_add=True) date_modified = models.DateTimeField(_('modified at'), auto_now=True) translations = TranslatedFields( name=models.CharField(_('name'), max_length=255), slug=models.SlugField(_('slug'), blank=True, db_index=True), meta={'unique_together': (('language_code', 'slug'),)} ) objects = TranslationManager() class Meta: verbose_name = _('blog category') verbose_name_plural = _('blog categories') @property def count(self): return self.blog_posts.filter(publish=True).count() def __unicode__(self): return self.safe_translation_getter('name') def save(self, *args, **kwargs): super(BlogCategory, self).save(*args, **kwargs) for lang in self.get_available_languages(): self.set_current_language(lang) if not self.slug and self.name: self.slug = slugify(force_text(self.name)) self.save_translations()
class Category(MPTTModel, TranslatableModel): parent = TreeForeignKey('self', null=True, blank=True,) translations = TranslatedFields( name=models.CharField(max_length=60, verbose_name=_('Name')), slug=models.SlugField(verbose_name=_('Slug'), unique=True,), ) order = models.IntegerField(default=0) objects = TranslationManager() def __str__(self): return "{}".format(self.name) class MPTTMeta: level_attr = 'mptt_level' class Meta: verbose_name = _('Category') verbose_name_plural = _('Categories') def get_slug_list(self): try: ancestors = self.get_ancestors(include_self=self) except: ancestors = [] else: ancestors = [i.slug for i in ancestors] slugs = [] for i in range(len(ancestors)): slugs.append('/'.join(ancestors[i + 1])) return slugs
class Category(MPTTModel, TranslatableModel): parent = TreeForeignKey( 'self', null=True, blank=True, ) translations = TranslatedFields( name=models.CharField(max_length=60, verbose_name=_('Name')), slug=models.SlugField( verbose_name=_('Slug'), unique=True, ), ) order = models.IntegerField(default=0) objects = TranslationManager() def __str__(self): return "{}".format(self.safe_translation_getter('name')) class MPTTMeta: level_attr = 'mptt_level' class Meta: verbose_name = _('Category') verbose_name_plural = _('Categories') def get_slug_list(self): try: ancestors = self.get_ancestors(include_self=self) except: ancestors = [] else: ancestors = [i.slug for i in ancestors] slugs = [] for i in range(len(ancestors)): slugs.append('/'.join(ancestors[i + 1])) return slugs def get_absolute_url(self): return reverse_lazy('products:product_list', args=[self.safe_translation_getter('slug')]) @property def get_related_products(self): cats = [self.pk] if self.get_children(): for child in self.get_children(): cats.append(child.pk) return Product.objects.filter(category__in=cats) @property def get_related_four_products(self): cats = [self.pk] if self.get_children(): for child in self.get_children(): cats.append(child.pk) return Product.objects.filter(category__in=cats)[0:4]
class Menu(TranslatableModel): translations = TranslatedFields( name=models.CharField(max_length=60, verbose_name=_('Name')), slug=models.SlugField(max_length=60, verbose_name=_('Slug')), ) order = models.IntegerField(default=0, verbose_name=_('Order')) objects = TranslationManager() def __str__(self): return "{}".format(self.name)
class Static(TranslatableModel): translations = TranslatedFields( name=models.CharField(max_length=60, verbose_name=_('Name')), slug=models.SlugField(max_length=60, verbose_name=_('Slug'), unique=True), body=RichTextUploadingField() ) image = FilerImageField(null=True, blank=True) objects = TranslationManager() def __str__(self): return "{}".format(self.safe_translation_getter('name'))
class Color(TranslatableModel): translations = TranslatedFields(name=models.CharField(max_length=60), ) color = ColorField(default='#FF0000') objects = TranslationManager() def __str__(self): return "{}".format(self.name) class Meta: verbose_name = _('Color') verbose_name_plural = _('Colors')
class Banner(TranslatableModel): translations = TranslatedFields( name=models.CharField(max_length=60, verbose_name=_('Name')), url=models.CharField(max_length=60, verbose_name=_('Url'), null=True), body=RichTextUploadingField(null=True), ) banner = FilerImageField(null=True, related_name='banner') order = models.IntegerField(default=0, verbose_name=_('Order')) objects = TranslationManager() def __str__(self): return "{}".format(self.safe_translation_getter('name'))
class AppCategory(TranslatableModel): """ App category """ parent = models.ForeignKey('self', verbose_name=_('parent'), null=True, blank=True) date_created = models.DateTimeField(_('created at'), auto_now_add=True) date_modified = models.DateTimeField(_('modified at'), auto_now=True) translations = TranslatedFields( name=models.CharField(_('name'), max_length=255), slug=models.SlugField(_('slug'), blank=True, db_index=True), meta={'unique_together': [ ( 'slug', 'language_code', ), ]}) objects = TranslationManager() class Meta: verbose_name = _('app category') verbose_name_plural = _('app categories') @property def count(self): print dir(self) return self.app_terms_categories.filter(publish=True).count() def get_absolute_url(self): lang = get_language() if self.has_translation(lang): slug = self.safe_translation_getter('slug', language_code=lang) return reverse('app:termsagreements-category', kwargs={'category': slug}) # in case category doesn't exist in this language, gracefully fallback # to termsagreements-latest return reverse('app:termsagreements-latest') def __str__(self): return self.safe_translation_getter('name') def save(self, *args, **kwargs): super(AppCategory, self).save(*args, **kwargs) for lang in self.get_available_languages(): self.set_current_language(lang) if not self.slug and self.name: self.slug = slugify(force_text(self.name)) self.save_translations()
class Banner(TranslatableModel): translations = TranslatedFields( name=models.CharField(max_length=60, verbose_name=_('Name')), slug=models.SlugField(max_length=60, verbose_name=_('Slug')), image=models.ImageField(upload_to='banners/%Y/%m/%d', verbose_name=_('Image')), ) order = models.IntegerField(default=0, verbose_name=_('Order')) objects = TranslationManager() def __str__(self): return "{}".format(self.name)
class Feature(TranslatableModel): translations = TranslatedFields( name=models.CharField(max_length=60, verbose_name=_('Name'), unique=True), slug=models.SlugField(verbose_name=_('Slug'), unique=True, ), ) objects = TranslationManager() class Meta: verbose_name = _('Feature') verbose_name_plural = _('Features') def __str__(self): return "{}".format(self.safe_translation_getter('name'))
class Static(TranslatableModel): translations = TranslatedFields( name=models.CharField(max_length=60, verbose_name=_('Name')), slug=models.SlugField(max_length=60, verbose_name=_('Slug')), image=models.ImageField( upload_to='banners/%Y/%m/%d', verbose_name=_('Image'), null=True, blank=True, ), body=RichTextUploadingField()) objects = TranslationManager() def __str__(self): return "{}".format(self.name)
class Menu(MPTTModel, TranslatableModel): parent = TreeForeignKey('self', null=True, blank=True, on_delete=models.CASCADE) translations = TranslatedFields( title=models.CharField(max_length=254), slug=models.CharField(max_length=254) ) objects = TranslationManager() def __str__(self): return self.title class MPTTMeta: level_attr = 'mptt_level' def get_absolute_url(self): return reverse('basic:static_page', args=[self.get_current_language(), self.safe_translation_getter('slug')])
class News(TranslatableModel): translations = TranslatedFields( name=models.CharField(max_length=60, verbose_name=_('Name')), slug=models.SlugField(max_length=60, verbose_name=_('Slug'), unique=True), body=RichTextUploadingField() ) image = FilerImageField(null=True) published_at = models.DateTimeField() objects = TranslationManager() class Meta: verbose_name = _('News') verbose_name_plural = _('News') def get_absolute_url(self): return reverse_lazy('main:news_detail', args=[self.safe_translation_getter('slug')])
class StaticFooterPage(TranslatableModel): TARGET_CHOICES = ( (0, 'For clients'), (1, 'For partners'), ) translations = TranslatedFields( name=models.CharField(max_length=60, verbose_name=_('Name')), slug=models.SlugField(max_length=60, verbose_name=_('Slug')), body=RichTextUploadingField()) menu_type = models.IntegerField(choices=TARGET_CHOICES, blank=True, null=True) # target_type = models.CharField(choices=TARGET_CHOICES, max_length=12, default='clients') image = models.ImageField(upload_to='banners/%Y/%m/%d', verbose_name=_('Image')), objects = TranslationManager() def __str__(self): return "{}".format(self.name)