feat: 针对地坪的修改
This commit is contained in:
parent
8c66a61509
commit
cfaadc035a
|
@ -0,0 +1,47 @@
|
||||||
|
# Generated by Django 3.2.12 on 2024-09-14 03:03
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
import django.db.models.deletion
|
||||||
|
import django.utils.timezone
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('cms', '0014_auto_20231207_2146'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.CreateModel(
|
||||||
|
name='CompanyInfo',
|
||||||
|
fields=[
|
||||||
|
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||||
|
('create_time', models.DateTimeField(default=django.utils.timezone.now, help_text='创建时间', verbose_name='创建时间')),
|
||||||
|
('update_time', models.DateTimeField(auto_now=True, help_text='修改时间', verbose_name='修改时间')),
|
||||||
|
('is_delete', models.BooleanField(default=False, help_text='删除标记', verbose_name='删除标记')),
|
||||||
|
('company_name', models.CharField(max_length=50, verbose_name='父公司名称')),
|
||||||
|
('edu_points', models.FloatField(blank=True, null=True, verbose_name='教育积分')),
|
||||||
|
('co_sponsor_points', models.FloatField(blank=True, null=True, verbose_name='协办大赛积分')),
|
||||||
|
('sum_points', models.FloatField(blank=True, null=True, verbose_name='总积分')),
|
||||||
|
],
|
||||||
|
options={
|
||||||
|
'abstract': False,
|
||||||
|
},
|
||||||
|
),
|
||||||
|
migrations.CreateModel(
|
||||||
|
name='ChildrenCompany',
|
||||||
|
fields=[
|
||||||
|
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||||
|
('create_time', models.DateTimeField(default=django.utils.timezone.now, help_text='创建时间', verbose_name='创建时间')),
|
||||||
|
('update_time', models.DateTimeField(auto_now=True, help_text='修改时间', verbose_name='修改时间')),
|
||||||
|
('is_delete', models.BooleanField(default=False, help_text='删除标记', verbose_name='删除标记')),
|
||||||
|
('child_company_name', models.CharField(max_length=50, verbose_name='子公司名称')),
|
||||||
|
('child_edu_points', models.FloatField(blank=True, null=True, verbose_name='教育积分')),
|
||||||
|
('child_co_sponsor_points', models.FloatField(blank=True, null=True, verbose_name='协办大赛积分')),
|
||||||
|
('parent_compnay', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='cms.companyinfo', verbose_name='父公司')),
|
||||||
|
],
|
||||||
|
options={
|
||||||
|
'abstract': False,
|
||||||
|
},
|
||||||
|
),
|
||||||
|
]
|
|
@ -0,0 +1,18 @@
|
||||||
|
# Generated by Django 3.2.12 on 2024-09-14 06:03
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('cms', '0015_auto_20240914_1103'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.RenameField(
|
||||||
|
model_name='childrencompany',
|
||||||
|
old_name='parent_compnay',
|
||||||
|
new_name='parent_comany',
|
||||||
|
),
|
||||||
|
]
|
|
@ -0,0 +1,18 @@
|
||||||
|
# Generated by Django 3.2.12 on 2024-09-14 06:05
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('cms', '0016_auto_20240914_1403'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.RenameField(
|
||||||
|
model_name='childrencompany',
|
||||||
|
old_name='parent_comany',
|
||||||
|
new_name='parent_company',
|
||||||
|
)
|
||||||
|
]
|
|
@ -0,0 +1,22 @@
|
||||||
|
# Generated by Django 3.2.12 on 2024-09-18 03:09
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('cms', '0017_auto_20240914_1405'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.RemoveField(
|
||||||
|
model_name='childrencompany',
|
||||||
|
name='child_company_name',
|
||||||
|
),
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='article',
|
||||||
|
name='type',
|
||||||
|
field=models.IntegerField(default=0, verbose_name='类型'),
|
||||||
|
),
|
||||||
|
]
|
|
@ -11,6 +11,7 @@ class Article(CommonModel):
|
||||||
content = models.TextField(verbose_name='内容', blank=True)
|
content = models.TextField(verbose_name='内容', blank=True)
|
||||||
ifrom = models.CharField(max_length=60, verbose_name='来源')
|
ifrom = models.CharField(max_length=60, verbose_name='来源')
|
||||||
is_top = models.BooleanField('置顶', default=False)
|
is_top = models.BooleanField('置顶', default=False)
|
||||||
|
type = models.IntegerField('类型', default=0)
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
verbose_name = '文章'
|
verbose_name = '文章'
|
||||||
|
@ -63,5 +64,26 @@ class Threshold(CommonModel):
|
||||||
cas = models.CharField('cas号', max_length=20)
|
cas = models.CharField('cas号', max_length=20)
|
||||||
|
|
||||||
|
|
||||||
|
class CompanyInfo(CommonModel):
|
||||||
|
company_name = models.CharField('父公司名称', max_length=50)
|
||||||
|
edu_points = models.FloatField('教育积分', null=True, blank=True)
|
||||||
|
co_sponsor_points = models.FloatField('协办大赛积分', null=True, blank=True)
|
||||||
|
sum_points = models.FloatField('总积分', null=True, blank=True)
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
return self.company_name
|
||||||
|
|
||||||
|
|
||||||
|
class ChildrenCompany(CommonModel):
|
||||||
|
child_edu_points = models.FloatField('教育积分', null=True, blank=True)
|
||||||
|
child_co_sponsor_points = models.FloatField('协办大赛积分', null=True, blank=True)
|
||||||
|
parent_company = models.ForeignKey(CompanyInfo, verbose_name='父公司', on_delete=models.CASCADE)
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
return self.child_company_name
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
from rest_framework import serializers
|
from rest_framework import serializers
|
||||||
from .models import Article, Material, Source, Threshold
|
from .models import Article, Material, Source, Threshold, CompanyInfo, ChildrenCompany
|
||||||
from utils.constants import EXCLUDE_FIELDS_BASE
|
from utils.constants import EXCLUDE_FIELDS_BASE
|
||||||
|
|
||||||
|
|
||||||
|
@ -48,3 +48,64 @@ class ThresholdSerializer(serializers.ModelSerializer):
|
||||||
|
|
||||||
class PathSerializer(serializers.Serializer):
|
class PathSerializer(serializers.Serializer):
|
||||||
path = serializers.CharField(label='文件地址')
|
path = serializers.CharField(label='文件地址')
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
class CompanyInfoSerializer(serializers.ModelSerializer):
|
||||||
|
# children_companies = serializers.SerializerMethodField()
|
||||||
|
class Meta:
|
||||||
|
model = CompanyInfo
|
||||||
|
fields = '__all__'
|
||||||
|
|
||||||
|
# def get_children_companies(self, obj):
|
||||||
|
# children = ChildrenCompany.objects.filter(parent_company=obj)
|
||||||
|
# return ChildrenCompanySerializer(children, many=True).data
|
||||||
|
|
||||||
|
def create(self, validated_data):
|
||||||
|
instance = super().create(validated_data)
|
||||||
|
instance.sum_points = validated_data["edu_points"] + validated_data["co_sponsor_points"]
|
||||||
|
instance.save()
|
||||||
|
return instance
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
class ChildrenCompanySerializer(serializers.ModelSerializer):
|
||||||
|
parent_company_name = serializers.StringRelatedField(source='parent_company.company_name', read_only=True)
|
||||||
|
class Meta:
|
||||||
|
model = ChildrenCompany
|
||||||
|
fields = '__all__'
|
||||||
|
|
||||||
|
def create(self, validated_data):
|
||||||
|
instance = super().create(validated_data)
|
||||||
|
parent_company = instance.parent_company
|
||||||
|
children = ChildrenCompany.objects.filter(parent_company=parent_company)
|
||||||
|
|
||||||
|
total_edu = sum(c.child_edu_points or 0 for c in children)
|
||||||
|
total_sponsor = sum(c.child_co_sponsor_points or 0 for c in children)
|
||||||
|
# 加上未保存的分数
|
||||||
|
parent_company.edu_points = total_edu
|
||||||
|
parent_company.co_sponsor_points = total_sponsor
|
||||||
|
parent_company.sum_points = parent_company.edu_points + parent_company.co_sponsor_points
|
||||||
|
parent_company.save()
|
||||||
|
return instance
|
||||||
|
|
||||||
|
|
||||||
|
# # # 定义信号处理器
|
||||||
|
# from django.db.models.signals import pre_save
|
||||||
|
# from django.dispatch import receiver
|
||||||
|
# from .models import ChildrenCompany, CompanyInfo
|
||||||
|
|
||||||
|
|
||||||
|
# @receiver(pre_save, sender=ChildrenCompany)
|
||||||
|
# def update_parent_sum_points(sender, instance, **kwargs):
|
||||||
|
# parent_company = instance.parent_company
|
||||||
|
# child_companies = ChildrenCompany.objects.filter(parent_company=parent_company)
|
||||||
|
# # 计算子公司的积分
|
||||||
|
# child_edu_sum = sum(c.child_edu_points or 0 for c in child_companies)
|
||||||
|
# child_co_sponsor_sum = sum(c.child_co_sponsor_points or 0 for c in child_companies)
|
||||||
|
|
||||||
|
# # 更新父公司的总积分
|
||||||
|
# parent_company.edu_points = child_edu_sum
|
||||||
|
# parent_company.co_sponsor_points = child_co_sponsor_sum
|
||||||
|
# parent_company.sum_points = child_edu_sum + child_co_sponsor_sum
|
||||||
|
# parent_company.save()
|
|
@ -1,5 +1,5 @@
|
||||||
from django.urls import path,include
|
from django.urls import path,include
|
||||||
from .views import ArticleViewSet, MaterialViewSet, SourceViewSet, ThresholdViewSet
|
from .views import ArticleViewSet, MaterialViewSet, SourceViewSet, ThresholdViewSet, ConpamyInfoViewSet, ChildrenCompanyViewSet
|
||||||
from rest_framework import routers
|
from rest_framework import routers
|
||||||
|
|
||||||
|
|
||||||
|
@ -8,6 +8,8 @@ router.register('article', ArticleViewSet, basename="article")
|
||||||
router.register('material', MaterialViewSet, basename="material")
|
router.register('material', MaterialViewSet, basename="material")
|
||||||
router.register('source', SourceViewSet, basename='source')
|
router.register('source', SourceViewSet, basename='source')
|
||||||
router.register('threshold', ThresholdViewSet, basename='threshold')
|
router.register('threshold', ThresholdViewSet, basename='threshold')
|
||||||
|
router.register('company', ConpamyInfoViewSet, basename='company')
|
||||||
|
router.register('childcomany', ChildrenCompanyViewSet, basename='child_company')
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
path('', include(router.urls)),
|
path('', include(router.urls)),
|
||||||
|
|
|
@ -11,8 +11,8 @@ from openpyxl import load_workbook, Workbook
|
||||||
from django.db import transaction
|
from django.db import transaction
|
||||||
# Create your views here.
|
# Create your views here.
|
||||||
|
|
||||||
from .models import Article, Material, Source, Threshold
|
from .models import Article, Material, Source, Threshold, CompanyInfo, ChildrenCompany
|
||||||
from .serializers import ArticelSerializer, ArticelListSerializer, MaterialSerializer, SourceSerializer, ThresholdSerializer, PathSerializer
|
from .serializers import ArticelSerializer, ArticelListSerializer, MaterialSerializer, SourceSerializer, ThresholdSerializer, PathSerializer, CompanyInfoSerializer, ChildrenCompanySerializer
|
||||||
from utils.custom import CommonPagination
|
from utils.custom import CommonPagination
|
||||||
class ArticleViewSet(ModelViewSet):
|
class ArticleViewSet(ModelViewSet):
|
||||||
"""
|
"""
|
||||||
|
@ -25,9 +25,10 @@ class ArticleViewSet(ModelViewSet):
|
||||||
serializer_class = ArticelSerializer
|
serializer_class = ArticelSerializer
|
||||||
pagination_class = CommonPagination
|
pagination_class = CommonPagination
|
||||||
filter_backends = [DjangoFilterBackend,SearchFilter, OrderingFilter]
|
filter_backends = [DjangoFilterBackend,SearchFilter, OrderingFilter]
|
||||||
search_fields = ['title','content']
|
search_fields = ['title','content', 'types']
|
||||||
ordering_fields = ['title','update_time']
|
ordering_fields = ['title','update_time']
|
||||||
ordering = ['-is_top', '-update_time']
|
ordering = ['-is_top', '-update_time']
|
||||||
|
filterset_fields = ['type']
|
||||||
|
|
||||||
def get_serializer_class(self):
|
def get_serializer_class(self):
|
||||||
if self.action=='list':
|
if self.action=='list':
|
||||||
|
@ -45,6 +46,38 @@ class ArticleViewSet(ModelViewSet):
|
||||||
instance.save()
|
instance.save()
|
||||||
return Response(status=status.HTTP_200_OK)
|
return Response(status=status.HTTP_200_OK)
|
||||||
|
|
||||||
|
|
||||||
|
class ConpamyInfoViewSet(ModelViewSet):
|
||||||
|
"""
|
||||||
|
父公司:增删改查
|
||||||
|
"""
|
||||||
|
perms_map = [
|
||||||
|
{'get': '*'}, {'post': 'article_create'},
|
||||||
|
{'put': 'article_update'}, {'delete': 'article_delete'}]
|
||||||
|
queryset = CompanyInfo.objects.filter(is_delete=0).all()
|
||||||
|
serializer_class = CompanyInfoSerializer
|
||||||
|
pagination_class = CommonPagination
|
||||||
|
filter_backends = [DjangoFilterBackend,SearchFilter, OrderingFilter]
|
||||||
|
search_fields = ['company_name']
|
||||||
|
ordering_fields = ['update_time']
|
||||||
|
ordering = ['-sum_points']
|
||||||
|
|
||||||
|
|
||||||
|
class ChildrenCompanyViewSet(ModelViewSet):
|
||||||
|
"""
|
||||||
|
子公司:增删改查
|
||||||
|
"""
|
||||||
|
perms_map = [
|
||||||
|
{'get': '*'}, {'post': 'article_create'},
|
||||||
|
{'put': 'article_update'}, {'delete': 'article_delete'}]
|
||||||
|
queryset = ChildrenCompany.objects.filter(is_delete=0).all()
|
||||||
|
serializer_class = ChildrenCompanySerializer
|
||||||
|
pagination_class = CommonPagination
|
||||||
|
filter_backends = [DjangoFilterBackend,SearchFilter, OrderingFilter]
|
||||||
|
filterset_fields = ['parent_company']
|
||||||
|
ordering_fields = ['update_time']
|
||||||
|
ordering = ['-update_time']
|
||||||
|
|
||||||
class MaterialViewSet(ModelViewSet):
|
class MaterialViewSet(ModelViewSet):
|
||||||
"""
|
"""
|
||||||
资料:增删改查
|
资料:增删改查
|
||||||
|
|
|
@ -0,0 +1,23 @@
|
||||||
|
# Generated by Django 3.2.12 on 2024-09-19 08:05
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('crm', '0046_auto_20230407_1012'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='candidate',
|
||||||
|
name='gender',
|
||||||
|
field=models.CharField(blank=True, max_length=10, null=True, verbose_name='性别'),
|
||||||
|
),
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='candidate',
|
||||||
|
name='opllevel',
|
||||||
|
field=models.CharField(blank=True, max_length=60, null=True, verbose_name='职业等级'),
|
||||||
|
),
|
||||||
|
]
|
|
@ -129,6 +129,8 @@ class Candidate(CommonModel):
|
||||||
train_start_date = models.DateField('培训开始日期', null=True)
|
train_start_date = models.DateField('培训开始日期', null=True)
|
||||||
train_end_date = models.DateField('培训结束日期', null=True)
|
train_end_date = models.DateField('培训结束日期', null=True)
|
||||||
create_admin = models.ForeignKey(UserProfile, verbose_name="创建管理员", null=True, blank=True, on_delete=models.SET_NULL)
|
create_admin = models.ForeignKey(UserProfile, verbose_name="创建管理员", null=True, blank=True, on_delete=models.SET_NULL)
|
||||||
|
gender = models.CharField('性别', max_length=10, null=True, blank=True)
|
||||||
|
opllevel = models.CharField('职业等级',max_length=60, null=True, blank=True)
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
verbose_name = '证书'
|
verbose_name = '证书'
|
||||||
|
|
Loading…
Reference in New Issue