From 1ca89c6535fbc15b53b9a5d0fad8076503ad0860 Mon Sep 17 00:00:00 2001 From: RogerWork Date: Wed, 4 Jun 2025 17:11:28 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E8=B7=AF=E7=94=B1=EF=BC=8C?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=9C=80=E5=90=8E=E6=9B=B4=E6=96=B0=E6=97=B6?= =?UTF-8?q?=E9=97=B4=EF=BC=8C=E4=BC=98=E5=8C=96=E8=BF=94=E5=9B=9E=E7=9A=84?= =?UTF-8?q?=E6=9C=80=E5=90=8E=E6=9B=B4=E6=96=B0=E6=97=B6=E9=97=B4=E4=B8=BA?= =?UTF-8?q?=E6=9C=AC=E5=9C=B0=E6=97=B6=E9=97=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dingxin_toolbox_drf/urls.py | 1 + product/migrations/0002_prditem_update_at.py | 18 +++++++++++++ product/models.py | 1 + product/serializers.py | 13 ++++++++- product/urls.py | 28 ++++++++++++++++++++ 5 files changed, 60 insertions(+), 1 deletion(-) create mode 100644 product/migrations/0002_prditem_update_at.py create mode 100644 product/urls.py diff --git a/dingxin_toolbox_drf/urls.py b/dingxin_toolbox_drf/urls.py index 9c57425..cb2b5ac 100644 --- a/dingxin_toolbox_drf/urls.py +++ b/dingxin_toolbox_drf/urls.py @@ -27,6 +27,7 @@ urlpatterns = [ path('ec/', include('dspt_api.urls')), # 电商平台接口 path('', include('mock.urls')), path('docs/', include_docs_urls(title='接口文档')), + path('prd/', include('product.urls')), ] websocket_urlpatterns = [ diff --git a/product/migrations/0002_prditem_update_at.py b/product/migrations/0002_prditem_update_at.py new file mode 100644 index 0000000..dec6fa0 --- /dev/null +++ b/product/migrations/0002_prditem_update_at.py @@ -0,0 +1,18 @@ +# Generated by Django 4.2.7 on 2025-06-04 08:42 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('product', '0001_initial'), + ] + + operations = [ + migrations.AddField( + model_name='prditem', + name='update_at', + field=models.DateTimeField(auto_now=True, help_text='最后更新时间', verbose_name='最后更新时间'), + ), + ] diff --git a/product/models.py b/product/models.py index eb73d77..b2f6893 100644 --- a/product/models.py +++ b/product/models.py @@ -22,6 +22,7 @@ class PrdItem(models.Model): prd_doc_link = models.CharField(verbose_name='原型地址',max_length=100, help_text='原型地址') prd_comment = models.TextField(verbose_name='版本描述', help_text='版本描述') is_delete = models.BooleanField(verbose_name='删除状态', default=False, help_text='删除状态') + update_at = models.DateTimeField(verbose_name='最后更新时间', auto_now=True, help_text='最后更新时间') def __str__(self): return self.prd_version diff --git a/product/serializers.py b/product/serializers.py index 16eeed2..8cf8caa 100644 --- a/product/serializers.py +++ b/product/serializers.py @@ -1,4 +1,6 @@ +import pytz from rest_framework import serializers +from django.utils import timezone from product.models import * @@ -11,4 +13,13 @@ class ProjectSerializer(serializers.ModelSerializer): class PrdItemSerializer(serializers.ModelSerializer): class Meta: model = PrdItem - fields = ('id', 'project', 'prd_version', 'prd_doc_link', 'prd_comment', 'is_delete') \ No newline at end of file + fields = ('id', 'project', 'prd_version', 'prd_doc_link', 'prd_comment', 'is_delete', 'update_at') + + def to_representation(self, instance): + rep = super().to_representation(instance) + if self.fields.get('update_at'): + # 根据你的字段配置动态获取需要转换的字段 + original_time = getattr(instance, 'update_at') + local_tz = pytz.timezone('Asia/Shanghai') + rep['update_at'] = original_time.astimezone(local_tz).strftime('%Y-%m-%d %H:%M:%S') + return rep \ No newline at end of file diff --git a/product/urls.py b/product/urls.py new file mode 100644 index 0000000..0298b3c --- /dev/null +++ b/product/urls.py @@ -0,0 +1,28 @@ +""" +URL configuration for dingxin_toolbox_drf project. + +The `urlpatterns` list routes URLs to views. For more information please see: + https://docs.djangoproject.com/en/4.2/topics/http/urls/ +Examples: +Function views + 1. Add an import: from my_app import views + 2. Add a URL to urlpatterns: path('', views.home, name='home') +Class-based views + 1. Add an import: from other_app.views import Home + 2. Add a URL to urlpatterns: path('', Home.as_view(), name='home') +Including another URLconf + 1. Import the include() function: from django.urls import include, path + 2. Add a URL to urlpatterns: path('blog/', include('blog.urls')) +""" +from django.contrib import admin +from django.urls import path, include +from product import views + +urlpatterns = [ + path('project_list', views.ProjectViewSet.as_view({'get': 'list'}), name='project_list'), + path('prd_list', views.PrdItemViewSet.as_view({'get': 'list'}), name='prd_list'), + path('prd_add', views.PrdItemViewSet.as_view({'post': 'create'}), name='prd_create'), + path('prd_get//', views.PrdItemViewSet.as_view({'get': 'retrieve'}), name='prd_get'), + path('prd_update//', views.PrdItemViewSet.as_view({'put': 'update'}), name='prd_update'), + path('prd_delete//', views.PrdItemViewSet.as_view({'delete': 'destroy'}), name='prd_delete'), +]