作业证书增加bug
This commit is contained in:
parent
8cfd6e5f7d
commit
5823d4443c
|
@ -57,15 +57,14 @@ class OplWorkerCreateSerializer(CustomModelSerializer):
|
|||
certificates = validated_data.pop('certificates')
|
||||
if OplWorker.objects.filter(worker=validated_data['worker'], opl=validated_data['opl']).exists():
|
||||
raise ParseError('该成员已加入')
|
||||
with transaction.atomic():
|
||||
oplw = super().create(validated_data)
|
||||
for x in certificates:
|
||||
oplc, _ = OplCert.objects.get_or_create(opl_worker=oplw, certificate=x,
|
||||
defaults={'opl_worker': oplw, '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()
|
||||
oplw = super().create(validated_data)
|
||||
for x in certificates:
|
||||
oplc, _ = OplCert.objects.get_or_create(opl_worker=oplw, certificate=x,
|
||||
defaults={'opl_worker': oplw, '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
|
||||
|
||||
|
||||
|
@ -78,15 +77,14 @@ class OplWorkerUpdateSerializer(CustomModelSerializer):
|
|||
|
||||
def update(self, instance, validated_data):
|
||||
certificates = validated_data.pop('certificates')
|
||||
with transaction.atomic():
|
||||
oplw = super().update(instance, validated_data)
|
||||
for x in certificates:
|
||||
oplc, _ = OplCert.objects.get_or_create(opl_worker=oplw, certificate=x,
|
||||
defaults={'opl_worker': oplw, '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()
|
||||
oplw = super().update(instance, validated_data)
|
||||
for x in certificates:
|
||||
oplc, _ = OplCert.objects.get_or_create(opl_worker=oplw, certificate=x,
|
||||
defaults={'opl_worker': oplw, '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
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue