Skip to content

Commit

Permalink
fix: 修复序列化问题 TencentBlueKing#7626
Browse files Browse the repository at this point in the history
  • Loading branch information
guohelu committed Dec 10, 2024
1 parent cbb17a8 commit 113c6d6
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 41 deletions.
6 changes: 3 additions & 3 deletions gcloud/contrib/template_market/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@

@admin.register(models.TemplateSharedRecord)
class TemplateMarketAdmin(admin.ModelAdmin):
list_display = ["project_id", "template_id", "creator", "create_at", "extra_info"]
list_filter = ["project_id", "template_id", "creator", "create_at"]
search_fields = ["project_id", "creator"]
list_display = ["project_id", "template_id", "scene_instance_id", "creator", "create_at", "extra_info"]
list_filter = ["project_id", "creator", "create_at"]
search_fields = ["project_id", "template_id", "scene_instance_id", "creator"]
7 changes: 2 additions & 5 deletions gcloud/contrib/template_market/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Generated by Django 3.2.15 on 2024-12-09 12:51
# Generated by Django 3.2.15 on 2024-12-10 02:27

from django.db import migrations, models

Expand All @@ -16,10 +16,7 @@ class Migration(migrations.Migration):
("id", models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name="ID")),
("project_id", models.IntegerField(default=-1, help_text="项目 ID", verbose_name="项目 ID")),
("template_id", models.IntegerField(help_text="模版 ID", verbose_name="模版 ID")),
(
"scene_instance_id",
models.CharField(db_index=True, help_text="场景实例 ID", max_length=32, verbose_name="场景实例 ID"),
),
("scene_instance_id", models.IntegerField(db_index=True, help_text="场景实例 ID", verbose_name="场景实例 ID")),
("creator", models.CharField(default="", max_length=32, verbose_name="创建者")),
("create_at", models.DateTimeField(auto_now_add=True, verbose_name="创建时间")),
("extra_info", models.JSONField(blank=True, null=True, verbose_name="额外信息")),
Expand Down
2 changes: 1 addition & 1 deletion gcloud/contrib/template_market/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
class TemplateSharedRecord(models.Model):
project_id = models.IntegerField(_("项目 ID"), default=-1, help_text="项目 ID")
template_id = models.IntegerField(_("模版 ID"), help_text="模版 ID")
scene_instance_id = models.CharField(_("场景实例 ID"), max_length=32, db_index=True, help_text="场景实例 ID")
scene_instance_id = models.IntegerField(_("场景实例 ID"), db_index=True, help_text="场景实例 ID")
creator = models.CharField(_("创建者"), max_length=32, default="")
create_at = models.DateTimeField(_("创建时间"), auto_now_add=True)
extra_info = models.JSONField(_("额外信息"), blank=True, null=True)
Expand Down
33 changes: 1 addition & 32 deletions gcloud/contrib/template_market/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,15 @@
from rest_framework import serializers

from gcloud.constants import DATETIME_FORMAT
from gcloud.contrib.template_market.models import TemplateSharedRecord
from gcloud.tasktmpl3.models import TaskTemplate


class TemplatePreviewSerializer(serializers.ModelSerializer):
class TemplatePreviewSerializer(serializers.Serializer):
name = serializers.CharField(read_only=True, help_text="模板名称")
pipeline_tree = serializers.SerializerMethodField(read_only=True, help_text="pipeline_tree")

def get_pipeline_tree(self, obj):
return json.dumps(obj.pipeline_tree)

class Meta:
model = TaskTemplate
fields = ["name", "pipeline_tree"]


class TemplateSharedRecordSerializer(serializers.Serializer):
template_id = serializers.CharField(required=True, help_text="模板id")
Expand All @@ -42,28 +36,3 @@ class TemplateSharedRecordSerializer(serializers.Serializer):
creator = serializers.CharField(required=False, max_length=32, help_text="创建者")
create_at = serializers.DateTimeField(required=False, help_text="创建时间", format=DATETIME_FORMAT)
extra_info = serializers.JSONField(required=False, allow_null=True, help_text="额外信息")

def create(self, validated_data):
instance = TemplateSharedRecord.objects.create(
project_id=validated_data["project_id"],
template_id=validated_data["template_id"],
creator=validated_data.get("creator", ""),
extra_info=validated_data.get("extra_info"),
)
return instance

class Meta:
model = TemplateSharedRecord
fields = [
"project_id",
"template_id",
"creator",
"create_at",
"extra_info",
"name",
"code",
"category",
"risk_level",
"labels",
"usage_content",
]

0 comments on commit 113c6d6

Please sign in to comment.