def update(self, instance, validated_data): try: update_account(instance.account, validated_data.pop('account')) except KeyError: pass try: update_person(instance.person, validated_data.pop('person')) except KeyError: pass try: if instance.health is None: health = create_health(validated_data.pop('health')) assign_health(instance, health) else: update_health(instance, validated_data.pop('health')) except: pass instance.classroom_id = validated_data.get('classroom_id', instance.classroom_id) instance.status = validated_data.get('status', instance.status) instance.admission_year = validated_data.get('admission_year', instance.admission_year) instance.save() return instance
def update(self, instance, validated_data): try: update_person(instance.person, validated_data.pop('person')) except KeyError: pass instance.save() return instance
def update(self, instance, validated_data): try: update_person(instance.person, validated_data.pop('person')) except KeyError: pass instance.students.clear() for student in validated_data.pop('students'): instance.students.add(student) instance.save() return instance