WorkManager / Workspace
·
2026-01-08 22:42
업무 등록 시 등록자/수정자 컬럼 추가
완료
보통
개발
📚 Wiki
📝 업무 내용
| 시작일 | 종료 예정일(목표) | 실제 종료일(완료) |
|---|---|---|
| 2026-01-08 | 2026-01-08 | 2026-01-08 |
업무 등록 시 등록자/수정자 저장되도록 컬럼 추가 및 로직 변경
migrate 방법
1. models.py 에서 등록자에 null=True, blank=True 처리
2. 기본 마이그레이션 진행
3. 빈 migrate 파일 생성하여 사용자 정보 update 로직 작성
4. 마이그레이션 수행 후 등록자에 부여된 null, blank 모두 False 처리
5. 최종 마이그레이션 완료
빈 migrate 파일 생성 명령어 :
python manage.py makemigrations --empty works
🌳 하위 업무 (Sub-tasks)
추가
등록된 하위 업무가 없습니다.
📦 Reference Keeper
[Sample] Django Model Field Reference
https://docs.djangoproject.com/en/5.1/ref/models/fields/
💻 기술 명세
# 샘플 파일 경로 /usr/tmp/sample1.jsp\n/src/main/config/settings_sample.py
# 비어있는 migragte 파일에 추가가
from django.db import migrations
from django.conf import settings
def fill_author_data(apps, schema_editor):
# 모델을 직접 import 하지 않고 apps.get_model을 사용해야 안전
work = apps.get_model('works', 'Work')
# settings.AUTH_USER_MODEL은 보통 'app_label.ModelName' 형태입니다. (예: 'auth.User')
# 점(.)을 기준으로 앱 이름과 모델 이름을 분리합니다.
user_app_label, user_model_name = settings.AUTH_USER_MODEL.split('.')
# 분리한 이름으로 실제 모델 객체를 가져옵니다.
User = apps.get_model(user_app_label, user_model_name)
# 이제 User.objects.get() 등을 사용할 수 있습니다.
default_author = User.objects.first()
# author 가 없는 모든 객체 업데이트
# update() 를 사용하면 save() 보다 빠름
work.objects.filter(author__isnull=True).update(author=default_author)
class Migration(migrations.Migration):
dependencies = [
('works', '0022_work_author_work_update_author'),
]
operations = [
migrations.RunPython(fill_author_data),
]
-- 샘플 Query SELECT * FROM dual;