From 7683d2f19fe97b803c4cf27387eb731eb02dd57b Mon Sep 17 00:00:00 2001 From: Lin Yiying <114329417+simple597@users.noreply.github.com> Date: Thu, 16 Nov 2023 17:46:23 +0800 Subject: [PATCH] fix(list): address an issue where word lists are created out of order (#341) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * build: change ui Make the background more beautiful by changing django's native ui. * build: change ui Make the background more beautiful by changing django's native ui. * style: format settings.py * fix(list): address an issue where word lists are created out of order * fix(list): address an issue where word lists are created out of order * fix: adjust migrations * style(word): black it * chore: add venv * feat(rewards): add migrations * refactor: black * merge for ci --------- Co-authored-by: 林京 <12078257+lin-jing597@user.noreply.gitee.com> Co-authored-by: Norton-Lin <358154247@qq.com> Co-authored-by: sheeplin <1270610465@qq.com> --- .github/workflows/e2e.yml | 2 +- .gitignore | 3 +- .../0002_reward_verbose_name_plural.py | 28 ++++++++ hinghwa-dict-backend/word/admin.py | 5 ++ .../word/migrations/0005_list_admin.py | 16 +++++ .../word/migrations/0006_list_ship.py | 64 +++++++++++++++++++ hinghwa-dict-backend/word/models.py | 12 ++++ 7 files changed, 128 insertions(+), 2 deletions(-) create mode 100644 hinghwa-dict-backend/rewards/migrations/0002_reward_verbose_name_plural.py create mode 100644 hinghwa-dict-backend/word/migrations/0005_list_admin.py create mode 100644 hinghwa-dict-backend/word/migrations/0006_list_ship.py diff --git a/.github/workflows/e2e.yml b/.github/workflows/e2e.yml index 262c6a69..d204e8a5 100644 --- a/.github/workflows/e2e.yml +++ b/.github/workflows/e2e.yml @@ -26,7 +26,7 @@ jobs: - name: Start django service run: | cd hinghwa-dict-backend - python3 manage.py makemigrations + python3 manage.py makemigrations --merge --no-input python3 manage.py migrate DJANGO_SUPERUSER_PASSWORD=testtest123 python manage.py createsuperuser --username admin --email test@test.com --no-input DJANGO_SUPERUSER_PASSWORD=testtest222 python manage.py createsuperuser --username admin2 --email test@test.com --no-input diff --git a/.gitignore b/.gitignore index 013d12dc..3b7eb3b3 100644 --- a/.gitignore +++ b/.gitignore @@ -5,4 +5,5 @@ media material logs .env -db.sqlite3 \ No newline at end of file +db.sqlite3 +venv \ No newline at end of file diff --git a/hinghwa-dict-backend/rewards/migrations/0002_reward_verbose_name_plural.py b/hinghwa-dict-backend/rewards/migrations/0002_reward_verbose_name_plural.py new file mode 100644 index 00000000..b32e3c2b --- /dev/null +++ b/hinghwa-dict-backend/rewards/migrations/0002_reward_verbose_name_plural.py @@ -0,0 +1,28 @@ +# Generated by Django 3.1.14 on 2023-11-16 08:38 + +from django.db import migrations + + +class Migration(migrations.Migration): + dependencies = [ + ("rewards", "0001_initial"), + ] + + operations = [ + migrations.AlterModelOptions( + name="order", + options={"verbose_name": "订单", "verbose_name_plural": "订单"}, + ), + migrations.AlterModelOptions( + name="product", + options={"verbose_name": "商品", "verbose_name_plural": "商品"}, + ), + migrations.AlterModelOptions( + name="title", + options={"verbose_name": "头衔", "verbose_name_plural": "头衔"}, + ), + migrations.AlterModelOptions( + name="transaction", + options={"verbose_name": "积分记录", "verbose_name_plural": "积分记录"}, + ), + ] diff --git a/hinghwa-dict-backend/word/admin.py b/hinghwa-dict-backend/word/admin.py index fc7b780c..b0b2a787 100644 --- a/hinghwa-dict-backend/word/admin.py +++ b/hinghwa-dict-backend/word/admin.py @@ -183,6 +183,10 @@ class ApplicationAdmin(admin.ModelAdmin): raw_id_fields = ("contributor", "verifier", "word") +class WordsInlineAdmin(admin.TabularInline): + model = List.words.through + + class ListsAdmin(admin.ModelAdmin): list_display = [ "id", @@ -199,6 +203,7 @@ class ListsAdmin(admin.ModelAdmin): list_per_page = 50 # filter_horizontal = ["words_included_word"] raw_id_fields = ["words"] + inlines = (WordsInlineAdmin,) def include_words(self, obj): return [bt.word for bt in obj.words.all()] diff --git a/hinghwa-dict-backend/word/migrations/0005_list_admin.py b/hinghwa-dict-backend/word/migrations/0005_list_admin.py new file mode 100644 index 00000000..7466a2d9 --- /dev/null +++ b/hinghwa-dict-backend/word/migrations/0005_list_admin.py @@ -0,0 +1,16 @@ +# Generated by Django 3.1.14 on 2023-09-16 08:49 + +from django.db import migrations + + +class Migration(migrations.Migration): + dependencies = [ + ("word", "0004_word_list"), + ] + + operations = [ + migrations.AlterModelOptions( + name="list", + options={"verbose_name": "词单", "verbose_name_plural": "词单"}, + ), + ] diff --git a/hinghwa-dict-backend/word/migrations/0006_list_ship.py b/hinghwa-dict-backend/word/migrations/0006_list_ship.py new file mode 100644 index 00000000..c00beabb --- /dev/null +++ b/hinghwa-dict-backend/word/migrations/0006_list_ship.py @@ -0,0 +1,64 @@ +# Generated by Django 3.1.14 on 2023-11-16 08:38 + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + dependencies = [ + ("word", "0005_list_admin"), + ] + + operations = [ + migrations.AlterField( + model_name="list", + name="name", + field=models.CharField(blank=True, max_length=30, verbose_name="词单名称"), + ), + migrations.CreateModel( + name="ListShip", + fields=[ + ( + "id", + models.AutoField( + auto_created=True, + primary_key=True, + serialize=False, + verbose_name="ID", + ), + ), + ( + "li", + models.ForeignKey( + on_delete=django.db.models.deletion.CASCADE, to="word.list" + ), + ), + ( + "word", + models.ForeignKey( + on_delete=django.db.models.deletion.CASCADE, to="word.word" + ), + ), + ], + options={ + "verbose_name": "包含词", + "verbose_name_plural": "包含词", + "ordering": ["id"], + }, + ), + migrations.RemoveField( + model_name="list", + name="words", + ), + migrations.AddField( + model_name="list", + name="words", + field=models.ManyToManyField( + blank=True, + related_name="included_word", + through="word.ListShip", + to="word.Word", + verbose_name="词语", + ), + ), + ] diff --git a/hinghwa-dict-backend/word/models.py b/hinghwa-dict-backend/word/models.py index 9251d72e..ab193c98 100644 --- a/hinghwa-dict-backend/word/models.py +++ b/hinghwa-dict-backend/word/models.py @@ -4,6 +4,7 @@ from article.models import Article import re + # application是为了修改word而产生的 # 所以当word字段发生变化的时候,需要考虑修改application @@ -218,6 +219,7 @@ class List(models.Model): related_name="included_word", verbose_name="词语", blank=True, + through="ListShip", ) id = models.CharField(max_length=20, verbose_name="ID", primary_key=True) createTime = models.DateTimeField(blank=True, verbose_name="创建时间") @@ -227,3 +229,13 @@ class List(models.Model): class Meta: verbose_name_plural = "词单" verbose_name = "词单" + + +class ListShip(models.Model): + li = models.ForeignKey(List, on_delete=models.CASCADE) + word = models.ForeignKey(Word, on_delete=models.CASCADE) + + class Meta: + ordering = ["id"] + verbose_name_plural = "包含词" + verbose_name = "包含词"