作业证书增加bug
This commit is contained in:
parent
5823d4443c
commit
f63ae9c247
|
@ -57,14 +57,20 @@ class OplWorkerCreateSerializer(CustomModelSerializer):
|
||||||
certificates = validated_data.pop('certificates')
|
certificates = validated_data.pop('certificates')
|
||||||
if OplWorker.objects.filter(worker=validated_data['worker'], opl=validated_data['opl']).exists():
|
if OplWorker.objects.filter(worker=validated_data['worker'], opl=validated_data['opl']).exists():
|
||||||
raise ParseError('该成员已加入')
|
raise ParseError('该成员已加入')
|
||||||
oplw = super().create(validated_data)
|
with transaction.atomic():
|
||||||
for x in certificates:
|
oplw = super().create(validated_data)
|
||||||
oplc, _ = OplCert.objects.get_or_create(opl_worker=oplw, certificate=x,
|
for x in certificates:
|
||||||
defaults={'opl_worker': oplw, 'certificate': x})
|
oplc = OplCert.objects.filter(opl_worker=oplw, certificate=x).first()
|
||||||
for f in Certificate._meta.fields:
|
if oplc:
|
||||||
if f.name not in ['id']:
|
pass
|
||||||
setattr(oplc, f.name, getattr(x, f.name, None))
|
else:
|
||||||
oplc.save()
|
oplc = OplCert
|
||||||
|
oplc.opl_worker = oplw
|
||||||
|
oplc.certificate = x
|
||||||
|
for f in Certificate._meta.fields:
|
||||||
|
if f.name not in ['id']:
|
||||||
|
setattr(oplc, f.name, getattr(x, f.name, None))
|
||||||
|
oplc.save()
|
||||||
return oplw
|
return oplw
|
||||||
|
|
||||||
|
|
||||||
|
@ -77,14 +83,20 @@ class OplWorkerUpdateSerializer(CustomModelSerializer):
|
||||||
|
|
||||||
def update(self, instance, validated_data):
|
def update(self, instance, validated_data):
|
||||||
certificates = validated_data.pop('certificates')
|
certificates = validated_data.pop('certificates')
|
||||||
oplw = super().update(instance, validated_data)
|
with transaction.atomic():
|
||||||
for x in certificates:
|
oplw = super().update(instance, validated_data)
|
||||||
oplc, _ = OplCert.objects.get_or_create(opl_worker=oplw, certificate=x,
|
for x in certificates:
|
||||||
defaults={'opl_worker': oplw, 'certificate': x})
|
oplc = OplCert.objects.filter(opl_worker=oplw, certificate=x).first()
|
||||||
for f in Certificate._meta.fields:
|
if oplc:
|
||||||
if f.name not in ['id']:
|
pass
|
||||||
setattr(oplc, f.name, getattr(x, f.name, None))
|
else:
|
||||||
oplc.save()
|
oplc = OplCert
|
||||||
|
oplc.opl_worker = oplw
|
||||||
|
oplc.certificate = x
|
||||||
|
for f in Certificate._meta.fields:
|
||||||
|
if f.name not in ['id']:
|
||||||
|
setattr(oplc, f.name, getattr(x, f.name, None))
|
||||||
|
oplc.save()
|
||||||
return oplw
|
return oplw
|
||||||
|
|
||||||
|
|
||||||
|
@ -133,6 +145,7 @@ class OplCreateUpdateSerializer(CustomModelSerializer):
|
||||||
|
|
||||||
class OplSerializer(CustomModelSerializer):
|
class OplSerializer(CustomModelSerializer):
|
||||||
cate_name = serializers.CharField(source='cate.name', read_only=True)
|
cate_name = serializers.CharField(source='cate.name', read_only=True)
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = Opl
|
model = Opl
|
||||||
fields = '__all__'
|
fields = '__all__'
|
||||||
|
|
Loading…
Reference in New Issue