作业证书增加bug
This commit is contained in:
parent
8cfd6e5f7d
commit
5823d4443c
|
@ -57,15 +57,14 @@ 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('该成员已加入')
|
||||||
with transaction.atomic():
|
oplw = super().create(validated_data)
|
||||||
oplw = super().create(validated_data)
|
for x in certificates:
|
||||||
for x in certificates:
|
oplc, _ = OplCert.objects.get_or_create(opl_worker=oplw, certificate=x,
|
||||||
oplc, _ = OplCert.objects.get_or_create(opl_worker=oplw, certificate=x,
|
defaults={'opl_worker': oplw, 'certificate': x})
|
||||||
defaults={'opl_worker': oplw, 'certificate': x})
|
for f in Certificate._meta.fields:
|
||||||
for f in Certificate._meta.fields:
|
if f.name not in ['id']:
|
||||||
if f.name not in ['id']:
|
setattr(oplc, f.name, getattr(x, f.name, None))
|
||||||
setattr(oplc, f.name, getattr(x, f.name, None))
|
oplc.save()
|
||||||
oplc.save()
|
|
||||||
return oplw
|
return oplw
|
||||||
|
|
||||||
|
|
||||||
|
@ -78,15 +77,14 @@ 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')
|
||||||
with transaction.atomic():
|
oplw = super().update(instance, validated_data)
|
||||||
oplw = super().update(instance, validated_data)
|
for x in certificates:
|
||||||
for x in certificates:
|
oplc, _ = OplCert.objects.get_or_create(opl_worker=oplw, certificate=x,
|
||||||
oplc, _ = OplCert.objects.get_or_create(opl_worker=oplw, certificate=x,
|
defaults={'opl_worker': oplw, 'certificate': x})
|
||||||
defaults={'opl_worker': oplw, 'certificate': x})
|
for f in Certificate._meta.fields:
|
||||||
for f in Certificate._meta.fields:
|
if f.name not in ['id']:
|
||||||
if f.name not in ['id']:
|
setattr(oplc, f.name, getattr(x, f.name, None))
|
||||||
setattr(oplc, f.name, getattr(x, f.name, None))
|
oplc.save()
|
||||||
oplc.save()
|
|
||||||
return oplw
|
return oplw
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue