Skip to content

Commit

Permalink
feat(character): add type to Character (#358)
Browse files Browse the repository at this point in the history
* feat(character): add "type" to Character

* test(character): add test files

* style(character): reformat for black
  • Loading branch information
CapooL authored Mar 8, 2024
1 parent 1f32583 commit 7dfccd7
Show file tree
Hide file tree
Showing 8 changed files with 1,306 additions and 0 deletions.
1 change: 1 addition & 0 deletions hinghwa-dict-backend/word/character/dto/character_all.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,6 @@ def character_all(character: Character, word: Word, source: Pronunciation) -> di
"traditional": character.traditional,
"word": word,
"source": source,
"type": None if character.type is None else character.type,
}
return response
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,6 @@ def character_normal(character: Character) -> dict:
"county": character.county,
"town": character.town,
"traditional": character.traditional,
"type": None if character.type is None else character.type,
}
return response
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ def character_simple(character: Character) -> dict:
"traditional": character.traditional,
"word": {"id": word_id} if word else None,
"source": {"source": source_value} if source else None,
"type": None if character.type is None else character.type,
}
)

Expand Down
2 changes: 2 additions & 0 deletions hinghwa-dict-backend/word/character/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ def searchCharacters(request):
character_form = CharacterForm(body)
if character_form.is_valid():
character = character_form.save(commit=False)
if "type" in body:
character.type = body["type"]
character.save()
return JsonResponse({"id": character.id}, status=200)
else:
Expand Down
1 change: 1 addition & 0 deletions hinghwa-dict-backend/word/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class Meta:
"county",
"town",
"traditional",
"type",
)


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


class Migration(migrations.Migration):

dependencies = [
("word", "0006_list_ship"),
]

operations = [
migrations.AddField(
model_name="character",
name="type",
field=models.CharField(max_length=20, null=True, verbose_name="读音类型"),
),
]
1 change: 1 addition & 0 deletions hinghwa-dict-backend/word/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ class Character(models.Model):
county = models.CharField(max_length=100, verbose_name="县区")
town = models.CharField(max_length=100, verbose_name="乡镇")
traditional = models.CharField(max_length=30, verbose_name="繁体字", default="")
type = models.CharField(max_length=20, verbose_name="读音类型", null=True)

def clean(self):
self.shengmu = self.shengmu.strip()
Expand Down
Loading

0 comments on commit 7dfccd7

Please sign in to comment.