new
This commit is contained in:
@@ -41,7 +41,7 @@ class TopicSerializer(serializers.ModelSerializer):
|
||||
class Meta:
|
||||
model = Topic
|
||||
fields = [
|
||||
'id', 'title', 'content', 'author', 'author_info',
|
||||
'id', 'title', 'category', 'content', 'author', 'author_info',
|
||||
'related_product', 'product_info',
|
||||
'related_service', 'service_info',
|
||||
'related_course', 'course_info',
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
from rest_framework import viewsets, status, mixins, parsers
|
||||
from rest_framework import viewsets, status, mixins, parsers, filters
|
||||
from django_filters.rest_framework import DjangoFilterBackend
|
||||
from rest_framework.decorators import action
|
||||
from rest_framework.response import Response
|
||||
from rest_framework import serializers
|
||||
@@ -68,6 +69,11 @@ class TopicViewSet(viewsets.ModelViewSet):
|
||||
"""
|
||||
queryset = Topic.objects.all()
|
||||
serializer_class = TopicSerializer
|
||||
filter_backends = [filters.SearchFilter, filters.OrderingFilter, DjangoFilterBackend]
|
||||
search_fields = ['title', 'content']
|
||||
filterset_fields = ['category', 'is_pinned']
|
||||
ordering_fields = ['created_at', 'view_count']
|
||||
ordering = ['-is_pinned', '-created_at']
|
||||
|
||||
def perform_create(self, serializer):
|
||||
user = get_current_wechat_user(self.request)
|
||||
|
||||
Binary file not shown.
@@ -7,9 +7,14 @@ django.setup()
|
||||
from shop.models import ESP32Config
|
||||
|
||||
def populate():
|
||||
# 检查数据库是否已有数据,如果有则跳过,避免每次构建都重置
|
||||
if ESP32Config.objects.exists():
|
||||
print("ESP32Config data already exists, skipping population.")
|
||||
return
|
||||
|
||||
# 清除旧数据,避免重复累积
|
||||
# 注意:在生产环境中慎用 delete
|
||||
ESP32Config.objects.all().delete()
|
||||
# ESP32Config.objects.all().delete()
|
||||
|
||||
configs = [
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user