Skip to content

Commit

Permalink
feat(word):adding tags field
Browse files Browse the repository at this point in the history
  • Loading branch information
CapooL committed Mar 28, 2024
1 parent cca3b1c commit cd1b92f
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 2 deletions.
1 change: 1 addition & 0 deletions hinghwa-dict-backend/word/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class Meta:
"visibility",
"standard_ipa",
"standard_pinyin",
"tags",
)


Expand Down
15 changes: 15 additions & 0 deletions hinghwa-dict-backend/word/migrations/0009_word_tags.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from django.db import migrations, models


class Migration(migrations.Migration):
dependencies = [
("word", "0008_alter_word_related_words"),
]

operations = [
migrations.AddField(
model_name="word",
name="tags",
field=models.TextField(blank=True, default="[]", verbose_name="标签"),
),
]
4 changes: 3 additions & 1 deletion hinghwa-dict-backend/word/models.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import re

from django.contrib.auth.models import User
from django.db import models

from article.models import Article
import re


# application是为了修改word而产生的
Expand Down Expand Up @@ -36,6 +37,7 @@ class Word(models.Model):
related_articles = models.ManyToManyField(
Article, related_name="related_words", verbose_name="相关帖子", blank=True
)
tags = models.TextField(verbose_name="标签", blank=True, default="[]")

def __str__(self):
return self.word
Expand Down
6 changes: 5 additions & 1 deletion hinghwa-dict-backend/word/word/dto/word_all.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
# 可用于WD0101 WD0201
from ...models import Word
import json

from user.dto.user_simple import user_simple
from word.word.views import word2pronunciation
from ...models import Word


def word_all(word: Word) -> dict:
Expand All @@ -14,6 +16,7 @@ def word_all(word: Word) -> dict:
]
user = word.contributor
source = word2pronunciation(word)
tags_list = json.loads(word.tags.replace("'", '"'))
response = {
"id": word.id,
"word": word.word,
Expand All @@ -27,5 +30,6 @@ def word_all(word: Word) -> dict:
"related_articles": related_articles,
"views": word.views,
"source": source,
"tags": tags_list,
}
return response
4 changes: 4 additions & 0 deletions hinghwa-dict-backend/word/word/dto/word_normal.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import json

from ...models import Word


Expand All @@ -9,6 +11,7 @@ def word_normal(word: Word) -> dict:
{"id": article.id, "title": article.title}
for article in word.related_articles.all()
]
tags_list = json.loads(word.tags.replace("'", '"'))
response = {
"word": word.word,
"definition": word.definition,
Expand All @@ -18,5 +21,6 @@ def word_normal(word: Word) -> dict:
"related_articles": related_articles,
"standard_ipa": word.standard_ipa,
"standard_pinyin": word.standard_pinyin,
"tags": tags_list
}
return response
4 changes: 4 additions & 0 deletions hinghwa-dict-backend/word/word/dto/word_simple.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
# 用于WD0202
import json

from ...models import Word


def word_simple(word: Word) -> dict:
user = word.contributor
tags_list = json.loads(word.tags.replace("'", '"'))
response = {
"id": word.id,
"word": word.word,
Expand All @@ -14,5 +17,6 @@ def word_simple(word: Word) -> dict:
"views": word.views,
"standard_ipa": word.standard_ipa,
"standard_pinyin": word.standard_pinyin,
"tags": tags_list,
}
return response

0 comments on commit cd1b92f

Please sign in to comment.