diff --git a/task/challenge.py b/task/challenge.py index 1292fab..06c5a4e 100644 --- a/task/challenge.py +++ b/task/challenge.py @@ -68,6 +68,9 @@ def create_or_update(request, payload: ChallengeIn): item.content = payload.content item.score = payload.score item.is_public = payload.is_public + item.example_html = payload.example_html + item.example_css = payload.example_css + item.example_js = payload.example_js if item.author_id is None and request.user.is_authenticated: item.author = request.user item.save() diff --git a/task/migrations/0009_task_example_css_task_example_html_task_example_js.py b/task/migrations/0009_task_example_css_task_example_html_task_example_js.py new file mode 100644 index 0000000..ec9380d --- /dev/null +++ b/task/migrations/0009_task_example_css_task_example_html_task_example_js.py @@ -0,0 +1,28 @@ +# Generated by Django 6.0.1 on 2026-06-07 11:17 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('task', '0008_challenge_author'), + ] + + operations = [ + migrations.AddField( + model_name='task', + name='example_css', + field=models.TextField(blank=True, null=True, verbose_name='示例CSS'), + ), + migrations.AddField( + model_name='task', + name='example_html', + field=models.TextField(blank=True, null=True, verbose_name='示例HTML'), + ), + migrations.AddField( + model_name='task', + name='example_js', + field=models.TextField(blank=True, null=True, verbose_name='示例JS'), + ), + ] diff --git a/task/models.py b/task/models.py index 8d4e889..f6035d8 100644 --- a/task/models.py +++ b/task/models.py @@ -19,6 +19,9 @@ class Task(TimeStampedModel): verbose_name="类型", ) is_public = models.BooleanField(default=False, verbose_name="是否公开") + example_html = models.TextField(null=True, blank=True, verbose_name="示例HTML") + example_css = models.TextField(null=True, blank=True, verbose_name="示例CSS") + example_js = models.TextField(null=True, blank=True, verbose_name="示例JS") class Meta: unique_together = ("display", "task_type") diff --git a/task/schemas.py b/task/schemas.py index b7139fb..5163ee9 100644 --- a/task/schemas.py +++ b/task/schemas.py @@ -20,6 +20,9 @@ class TutorialIn(Schema): title: str content: str is_public: bool = False + example_html: Optional[str] = None + example_css: Optional[str] = None + example_js: Optional[str] = None class ChallengeSlim(Schema): @@ -49,3 +52,6 @@ class ChallengeIn(Schema): content: str score: int = 0 is_public: bool = False + example_html: Optional[str] = None + example_css: Optional[str] = None + example_js: Optional[str] = None diff --git a/task/tutorial.py b/task/tutorial.py index 20e6eb4..c241aed 100644 --- a/task/tutorial.py +++ b/task/tutorial.py @@ -38,6 +38,9 @@ def create_or_update(request, payload: TutorialIn): item.title = payload.title item.content = payload.content item.is_public = payload.is_public + item.example_html = payload.example_html + item.example_css = payload.example_css + item.example_js = payload.example_js item.save() return {"message": "更新成功"} except Tutorial.DoesNotExist: