From 670a1f485ec881bf06d7971db3f0e2aeaf97572c Mon Sep 17 00:00:00 2001 From: Ivlev Denis Date: Mon, 5 Feb 2018 15:19:53 +0300 Subject: [PATCH] LIL-163-167. Add app Content with models Content, Image, Text, ImageText, Video --- apps/content/__init__.py | 0 apps/content/admin.py | 43 +++++++++ apps/content/apps.py | 6 ++ apps/content/migrations/0001_initial.py | 93 +++++++++++++++++++ .../migrations/0002_auto_20180205_1212.py | 29 ++++++ apps/content/migrations/__init__.py | 0 apps/content/models.py | 47 ++++++++++ apps/content/tests.py | 3 + apps/content/views.py | 2 + project/settings.py | 1 + 10 files changed, 224 insertions(+) create mode 100644 apps/content/__init__.py create mode 100644 apps/content/admin.py create mode 100644 apps/content/apps.py create mode 100644 apps/content/migrations/0001_initial.py create mode 100644 apps/content/migrations/0002_auto_20180205_1212.py create mode 100644 apps/content/migrations/__init__.py create mode 100644 apps/content/models.py create mode 100644 apps/content/tests.py create mode 100644 apps/content/views.py diff --git a/apps/content/__init__.py b/apps/content/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/apps/content/admin.py b/apps/content/admin.py new file mode 100644 index 00000000..e2f35219 --- /dev/null +++ b/apps/content/admin.py @@ -0,0 +1,43 @@ +from django.contrib import admin +from polymorphic.admin import ( + PolymorphicParentModelAdmin, + PolymorphicChildModelAdmin, + PolymorphicChildModelFilter, +) + +from .models import Content, Image, ImageText, Text, Video + + +class ContentChildAdmin(PolymorphicChildModelAdmin): + base_model = Content + + +@admin.register(Image) +class ImageAdmin(ContentChildAdmin): + base_model = Image + + +@admin.register(Text) +class TextAdmin(ContentChildAdmin): + base_model = Text + + +@admin.register(ImageText) +class ImageTextAdmin(ContentChildAdmin): + base_model = ImageText + + +@admin.register(Video) +class VideoAdmin(ContentChildAdmin): + base_model = Video + + +@admin.register(Content) +class ContentAdmin(PolymorphicParentModelAdmin): + base_model = Content + child_models = ( + Image, + Text, + ImageText, + Video + ) diff --git a/apps/content/apps.py b/apps/content/apps.py new file mode 100644 index 00000000..0905fca9 --- /dev/null +++ b/apps/content/apps.py @@ -0,0 +1,6 @@ +from django.apps import AppConfig + + +class ContentConfig(AppConfig): + name = 'content' + verbose_name = 'Контент' diff --git a/apps/content/migrations/0001_initial.py b/apps/content/migrations/0001_initial.py new file mode 100644 index 00000000..6b05bcc5 --- /dev/null +++ b/apps/content/migrations/0001_initial.py @@ -0,0 +1,93 @@ +# Generated by Django 2.0.2 on 2018-02-05 12:05 + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + initial = True + + dependencies = [ + ('course', '0020_auto_20180202_1716'), + ('contenttypes', '0002_remove_content_type_name'), + ] + + operations = [ + migrations.CreateModel( + name='Content', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('title', models.CharField(default='', max_length=100, verbose_name='Заголовок')), + ('position', models.PositiveSmallIntegerField(default=1, unique=True, verbose_name='Положение на странице')), + ], + options={ + 'abstract': False, + 'base_manager_name': 'objects', + }, + ), + migrations.CreateModel( + name='Image', + fields=[ + ('content_ptr', models.OneToOneField(auto_created=True, on_delete=django.db.models.deletion.CASCADE, parent_link=True, primary_key=True, serialize=False, to='content.Content')), + ('img', models.ImageField(upload_to='content/images', verbose_name='Изображение')), + ], + options={ + 'abstract': False, + 'base_manager_name': 'objects', + }, + bases=('content.content',), + ), + migrations.CreateModel( + name='ImageText', + fields=[ + ('content_ptr', models.OneToOneField(auto_created=True, on_delete=django.db.models.deletion.CASCADE, parent_link=True, primary_key=True, serialize=False, to='content.Content')), + ('img', models.ImageField(upload_to='content/images', verbose_name='Изображение')), + ('txt', models.TextField(default='', verbose_name='Текст')), + ], + options={ + 'abstract': False, + 'base_manager_name': 'objects', + }, + bases=('content.content',), + ), + migrations.CreateModel( + name='Text', + fields=[ + ('content_ptr', models.OneToOneField(auto_created=True, on_delete=django.db.models.deletion.CASCADE, parent_link=True, primary_key=True, serialize=False, to='content.Content')), + ('txt', models.TextField(default='', verbose_name='Текст')), + ], + options={ + 'abstract': False, + 'base_manager_name': 'objects', + }, + bases=('content.content',), + ), + migrations.CreateModel( + name='Video', + fields=[ + ('content_ptr', models.OneToOneField(auto_created=True, on_delete=django.db.models.deletion.CASCADE, parent_link=True, primary_key=True, serialize=False, to='content.Content')), + ('url', models.URLField(verbose_name='Ссылка')), + ], + options={ + 'abstract': False, + 'base_manager_name': 'objects', + }, + bases=('content.content',), + ), + migrations.AddField( + model_name='content', + name='course', + field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to='course.Course', verbose_name='Курс'), + ), + migrations.AddField( + model_name='content', + name='lesson', + field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to='course.Lesson', verbose_name='Урок'), + ), + migrations.AddField( + model_name='content', + name='polymorphic_ctype', + field=models.ForeignKey(editable=False, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='polymorphic_content.content_set+', to='contenttypes.ContentType'), + ), + ] diff --git a/apps/content/migrations/0002_auto_20180205_1212.py b/apps/content/migrations/0002_auto_20180205_1212.py new file mode 100644 index 00000000..8dfa06a8 --- /dev/null +++ b/apps/content/migrations/0002_auto_20180205_1212.py @@ -0,0 +1,29 @@ +# Generated by Django 2.0.2 on 2018-02-05 12:12 + +from django.db import migrations, models +import django.utils.timezone + + +class Migration(migrations.Migration): + + dependencies = [ + ('content', '0001_initial'), + ] + + operations = [ + migrations.AlterModelOptions( + name='content', + options={'verbose_name': 'Контент', 'verbose_name_plural': 'Контент'}, + ), + migrations.AddField( + model_name='content', + name='created_at', + field=models.DateTimeField(auto_now_add=True, default=django.utils.timezone.now), + preserve_default=False, + ), + migrations.AddField( + model_name='content', + name='update_at', + field=models.DateTimeField(auto_now=True), + ), + ] diff --git a/apps/content/migrations/__init__.py b/apps/content/migrations/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/apps/content/models.py b/apps/content/models.py new file mode 100644 index 00000000..4f02e846 --- /dev/null +++ b/apps/content/models.py @@ -0,0 +1,47 @@ +from django.db import models + +from polymorphic.models import PolymorphicModel + +from apps.course.models import Course, Lesson + + +class Content(PolymorphicModel): + course = models.ForeignKey( + Course, on_delete=models.CASCADE, + null=True, blank=True, + verbose_name='Курс' + ) + lesson = models.ForeignKey( + Lesson, on_delete=models.CASCADE, + null=True, blank=True, + verbose_name='Урок' + ) + title = models.CharField('Заголовок', max_length=100, default='') + position = models.PositiveSmallIntegerField( + 'Положение на странице', + default=1, unique=True + ) + + created_at = models.DateTimeField(auto_now_add=True) + update_at = models.DateTimeField(auto_now=True) + + class Meta: + verbose_name = 'Контент' + verbose_name_plural = 'Контент' + + +class Image(Content): + img = models.ImageField('Изображение', upload_to='content/images') + + +class Text(Content): + txt = models.TextField('Текст', default='') + + +class ImageText(Content): + img = models.ImageField('Изображение', upload_to='content/images') + txt = models.TextField('Текст', default='') + + +class Video(Content): + url = models.URLField('Ссылка') diff --git a/apps/content/tests.py b/apps/content/tests.py new file mode 100644 index 00000000..7ce503c2 --- /dev/null +++ b/apps/content/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/apps/content/views.py b/apps/content/views.py new file mode 100644 index 00000000..28002783 --- /dev/null +++ b/apps/content/views.py @@ -0,0 +1,2 @@ +from django.shortcuts import render + diff --git a/project/settings.py b/project/settings.py index 9615cd85..d52eb79d 100644 --- a/project/settings.py +++ b/project/settings.py @@ -53,6 +53,7 @@ INSTALLED_APPS = [ 'apps.notification', 'apps.payment', 'apps.course', + 'apps.content', ] if DEBUG: INSTALLED_APPS += ['silk']