리뷰 서비스 API 개발 - 정책 변경, 삭제 구현
DB 트랜잭션 처리 및 예외 처리 참고 (데이터 일관성 확보)
https://docs.djangoproject.com/en/3.0/topics/db/transactions/
https://wayhome25.github.io/django/2017/08/01/tsd7-django-query-database2/
https://docs.djangoproject.com/en/3.0/topics/db/transactions/
https://wayhome25.github.io/django/2017/08/01/tsd7-django-query-database2/
ManyToManyField의 업데이트: set 함수 사용
https://docs.djangoproject.com/en/3.0/ref/models/relations/#django.db.models.fields.related.RelatedManager.set
- clear flag는 set이 업데이트 시 기존 값이 한번에 많이 제거될 가능성이 클 때 True 설정하는 것이 좋을 듯함
https://docs.djangoproject.com/en/3.0/ref/models/relations/#django.db.models.fields.related.RelatedManager.set
- clear flag는 set이 업데이트 시 기존 값이 한번에 많이 제거될 가능성이 클 때 True 설정하는 것이 좋을 듯함
add, create, remove, clear, set 함수 호출 시에는 따로 save를 더 호출할 필요 없음
Note that add()
, create()
, remove()
, clear()
, and set()
all apply database changes immediately for all types of related fields. In other words, there is no need to call save()
on either end of the relationship.
If you use prefetch_related()
, the add()
, remove()
, clear()
, and set()
methods clear the prefetched cache.
외래키로 묶인 필드의 값을 업데이트 할 때에는 (해당 필드).save()를 따로 해주어야 함
예시:
예시:
rc = ReviewCycle.objects.get(pk=policy_id) rc.name = data['name'] rc.question.title = data['question']['title'] rc.question.description = data['question']['description'] rc.question.save() rc.save() rc.reviewees.set(data['reviewees'])