From 44d59fd5e6145784aea778de40a70367691ef13c Mon Sep 17 00:00:00 2001 From: Jan Szejko Date: Tue, 29 Nov 2016 12:56:50 +0100 Subject: [PATCH] add tag and category models --- .../catalogue/migrations/0006_category_tag.py | 35 +++++++++++++++++++ apps/catalogue/models/__init__.py | 6 ++-- apps/catalogue/models/tag.py | 20 +++++++++++ apps/catalogue/translation.py | 20 +++++++++++ redakcja/settings/common.py | 1 + requirements.txt | 1 + 6 files changed, 81 insertions(+), 2 deletions(-) create mode 100644 apps/catalogue/migrations/0006_category_tag.py create mode 100644 apps/catalogue/models/tag.py create mode 100644 apps/catalogue/translation.py diff --git a/apps/catalogue/migrations/0006_category_tag.py b/apps/catalogue/migrations/0006_category_tag.py new file mode 100644 index 00000000..1cd9186e --- /dev/null +++ b/apps/catalogue/migrations/0006_category_tag.py @@ -0,0 +1,35 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('catalogue', '0005_auto_20150505_1229'), + ] + + operations = [ + migrations.CreateModel( + name='Category', + fields=[ + ('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)), + ('label', models.CharField(max_length=64, verbose_name='category')), + ('label_en', models.CharField(max_length=64, null=True, verbose_name='category')), + ('label_pl', models.CharField(max_length=64, null=True, verbose_name='category')), + ('index', models.IntegerField()), + ], + ), + migrations.CreateModel( + name='Tag', + fields=[ + ('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)), + ('label', models.CharField(max_length=64, verbose_name='tag')), + ('label_en', models.CharField(max_length=64, null=True, verbose_name='tag')), + ('label_pl', models.CharField(max_length=64, null=True, verbose_name='tag')), + ('index', models.IntegerField()), + ('category', models.ForeignKey(to='catalogue.Category')), + ], + ), + ] diff --git a/apps/catalogue/models/__init__.py b/apps/catalogue/models/__init__.py index c2a067d7..a940dd00 100755 --- a/apps/catalogue/models/__init__.py +++ b/apps/catalogue/models/__init__.py @@ -7,11 +7,13 @@ from catalogue.models.template import Template from catalogue.models.document import Document from catalogue.models.plan import Plan from catalogue.models.publish_log import PublishRecord -#from catalogue.models.book import Book -#from catalogue.models.listeners import * +from catalogue.models.tag import Category, Tag +# from catalogue.models.book import Book +# from catalogue.models.listeners import * from django.contrib.auth.models import User as AuthUser + class User(AuthUser): class Meta: proxy = True diff --git a/apps/catalogue/models/tag.py b/apps/catalogue/models/tag.py new file mode 100644 index 00000000..b58f4581 --- /dev/null +++ b/apps/catalogue/models/tag.py @@ -0,0 +1,20 @@ +# -*- coding: utf-8 -*- +# +# This file is part of FNP-Redakcja, licensed under GNU Affero GPLv3 or later. +# Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information. +# +from __future__ import unicode_literals + +from django.db import models +from django.utils.translation import ugettext_lazy as _ + + +class Category(models.Model): + label = models.CharField(max_length=64, verbose_name=_('category')) + index = models.IntegerField() + + +class Tag(models.Model): + label = models.CharField(max_length=64, verbose_name=_('tag')) + category = models.ForeignKey(Category) + index = models.IntegerField() diff --git a/apps/catalogue/translation.py b/apps/catalogue/translation.py new file mode 100644 index 00000000..634a11bb --- /dev/null +++ b/apps/catalogue/translation.py @@ -0,0 +1,20 @@ +# -*- coding: utf-8 -*- +# +# This file is part of FNP-Redakcja, licensed under GNU Affero GPLv3 or later. +# Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information. +# + +from modeltranslation.translator import translator, TranslationOptions +from catalogue.models import Tag, Category + + +class TagTranslationOptions(TranslationOptions): + fields = ('label',) + + +class CategoryTranslationOptions(TranslationOptions): + fields = ('label',) + + +translator.register(Tag, TagTranslationOptions) +translator.register(Category, CategoryTranslationOptions) diff --git a/redakcja/settings/common.py b/redakcja/settings/common.py index 2989c1bb..cd230deb 100644 --- a/redakcja/settings/common.py +++ b/redakcja/settings/common.py @@ -125,6 +125,7 @@ INSTALLED_APPS = ( #'kombu.transport.django', 'fileupload', 'pipeline', + 'modeltranslation', 'catalogue', 'cover', diff --git a/requirements.txt b/requirements.txt index 0da55886..dd99f843 100644 --- a/requirements.txt +++ b/requirements.txt @@ -23,6 +23,7 @@ python-slugify django-forms-bootstrap jsonfield django-email-extras +django-modeltranslation>=0.12,<0.13 celery>=3.1.12,<3.2 kombu>3.0,<3.1 -- 2.20.1