update
This commit is contained in:
@@ -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()
|
||||
|
||||
@@ -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'),
|
||||
),
|
||||
]
|
||||
@@ -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")
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user