From 0d516765dfab8d276276b741be7699bc27d3e967 Mon Sep 17 00:00:00 2001 From: Mikan <72257910+Mikan-DS@users.noreply.github.com> Date: Wed, 2 Oct 2024 21:41:45 +0300 Subject: [PATCH] =?UTF-8?q?NP-2=20=D0=9A=D0=BD=D0=BE=D0=BF=D0=BA=D0=B8=20?= =?UTF-8?q?=D0=BD=D0=B0=20=D1=81=D1=82=D1=80=D0=B0=D0=BD=D0=B8=D1=86=D0=B0?= =?UTF-8?q?=D1=85=20item?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- NovelPlus/settings.py | 4 ++- common/admin.py | 12 ++++++-- .../migrations/0006_itemdatacontextbutton.py | 28 +++++++++++++++++++ common/models.py | 26 +++++++++++++++-- frontend/NovelPlus-frontend | 2 +- 5 files changed, 66 insertions(+), 6 deletions(-) create mode 100644 common/migrations/0006_itemdatacontextbutton.py diff --git a/NovelPlus/settings.py b/NovelPlus/settings.py index 93ab980..3a9aadd 100644 --- a/NovelPlus/settings.py +++ b/NovelPlus/settings.py @@ -10,6 +10,8 @@ For the full list of settings and their values, see https://docs.djangoproject.com/en/4.2/ref/settings/ """ +import os + from pathlib import Path from bd_config import default_database @@ -25,7 +27,7 @@ BASE_DIR = Path(__file__).resolve().parent.parent SECRET_KEY = 'django-insecure-+l_9olvm8c90$1y39)ukodf4_zdt^4vhdf+n+b=^i9tyl$wki%' # SECURITY WARNING: don't run with debug turned on in production! -DEBUG = False +DEBUG = bool(os.environ.get('LOCALDEV', False)) ALLOWED_HOSTS = [ "vnovelplus.temp.swtest.ru", diff --git a/common/admin.py b/common/admin.py index 28b3b39..453c072 100644 --- a/common/admin.py +++ b/common/admin.py @@ -1,16 +1,24 @@ from django.contrib import admin -from common.models import ItemData, ContextButtonType +from common.models import ItemData, ContextButtonType, ItemDataContextButton from common.signals import add_signals -# Register your models here. +class ItemDataButtonsInline(admin.TabularInline): + model = ItemDataContextButton + verbose_name = 'Контекстная кнопка информационного объекта' + verbose_name_plural = 'Контекстные кнопки информационных объектов' + extra = 1 + + class ItemDataAdmin(admin.ModelAdmin): list_display = ('title', "author", 'status', 'created_at', 'updated_at') search_fields = ('title', 'author') list_filter = ('collection', 'status') ordering = ('-created_at', '-updated_at', 'id') + inlines = [ItemDataButtonsInline] + admin.site.register(ItemData, ItemDataAdmin) diff --git a/common/migrations/0006_itemdatacontextbutton.py b/common/migrations/0006_itemdatacontextbutton.py new file mode 100644 index 0000000..37e7d0e --- /dev/null +++ b/common/migrations/0006_itemdatacontextbutton.py @@ -0,0 +1,28 @@ +# Generated by Django 4.2.16 on 2024-10-02 17:58 + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('common', '0005_contextbuttontype'), + ] + + operations = [ + migrations.CreateModel( + name='ItemDataContextButton', + fields=[ + ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('url', models.URLField(max_length=255, verbose_name='Ссылка')), + ('button_type', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='item_data_buttons', to='common.contextbuttontype', verbose_name='Тип кнопки')), + ('item_data', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='context_buttons', to='common.itemdata', verbose_name='Информационный объект')), + ], + options={ + 'verbose_name': 'Контекстная кнопка информационного объекта', + 'verbose_name_plural': 'Контекстные кнопки информационных объектов', + 'unique_together': {('item_data', 'button_type')}, + }, + ), + ] diff --git a/common/models.py b/common/models.py index 8a4bbea..2df16ae 100644 --- a/common/models.py +++ b/common/models.py @@ -89,7 +89,6 @@ class ItemData(models.Model): "description": self.description, } - @property def card_dict(self) -> typing.Dict[str, typing.Union[str, int, float, None]]: return { @@ -103,7 +102,7 @@ class ItemData(models.Model): card = self.card_dict card.update({ "status": self.status.verbose, - "updatedAt": self.updated_at.timestamp()//.001, + "updatedAt": self.updated_at.timestamp() // .001, "shortDescription": self.short_description }) @@ -121,3 +120,26 @@ class ContextButtonType(models.Model): ordering = ('verbose',) verbose_name = 'Тип контекстной кнопки' verbose_name_plural = 'Типы контекстных кнопок' + + +class ItemDataContextButton(models.Model): + item_data = models.ForeignKey(ItemData, + on_delete=models.CASCADE, + related_name='context_buttons', + verbose_name='Информационный объект' + ) + button_type = models.ForeignKey( + 'common.ContextButtonType', + on_delete=models.CASCADE, + related_name='item_data_buttons', + verbose_name='Тип кнопки' + ) + url = models.URLField(max_length=255, verbose_name='Ссылка') + + class Meta: + verbose_name = 'Контекстная кнопка информационного объекта' + verbose_name_plural = 'Контекстные кнопки информационных объектов' + unique_together = ('item_data', 'button_type') + + def __str__(self): + return f'{self.button_type.verbose} = {self.url}' diff --git a/frontend/NovelPlus-frontend b/frontend/NovelPlus-frontend index 356a49e..1c40384 160000 --- a/frontend/NovelPlus-frontend +++ b/frontend/NovelPlus-frontend @@ -1 +1 @@ -Subproject commit 356a49e52d06995cf44e7f13ec45b43072c5c0f9 +Subproject commit 1c4038447f20db87edaec1bdca8af395a8fd2bdf