Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | |
7 | 8 | 9 | 10 | 11 | 12 | 13 |
14 | 15 | 16 | 17 | 18 | 19 | 20 |
21 | 22 | 23 | 24 | 25 | 26 | 27 |
28 | 29 | 30 |
Tags
- 42seoul
- 프라이빗클라우드
- 동료학습
- 이노베이션아카데미
- c++
- 파이썬
- psql extension
- raycasting
- mistel키보드
- adminbro
- 텍스트북
- 스플릿키보드
- schema first
- GraphQL
- 엣지컴퓨팅
- 정렬
- 어셈블리어
- Cloud Spanner
- 부동소수점
- 자료구조
- 도커
- 42서울
- 창업
- 어셈블리
- 쿠버네티스
- SFINAE
- uuid-ossp
- 레이캐스팅
- enable_if
- 스타트업
Archives
- Today
- Total
written by yechoi
[django] shell로 커스텀 유저에 권한 주기 본문
반응형
쉘 실행
python manage.py shell
커스텀 유저에 admin 권한 주기
yechoi에게 admin 권한 주기
>>> from django.contrib.auth import get_user_model
>>> User = get_user_model()
>>> yechoi = User.objects.get(login="yechoi")
>>> print(yechoi)
yechoi
>>> yechoi.is_admin
False
>>> yechoi.is_admin = True
>>> yechoi.save()
>>> yechoi.is_admin
True
커스텀 유저에 커스텀 권한 주기
yechoi에게 can_write_permission 주기
>>> from django.contrib.auth import get_user_model
>>> User = get_user_model()
>>> yechoi = User.objects.get(login="yechoi")
>>> print(yechoi)
yechoi
>>> from django.contrib.contenttypes.models import ContentType
>>> from interview.models import Interview
>>> content_type = ContentType.objects.get_for_model(Interview)
>>> from django.contrib.auth.models import Permission
>>> permission = Permission.objects.get(codename='can_write_interview', content_type=content_type)
>>> yechoi.user_permissions.add(permission)
>>> yechoi.has_perm('interview.can_write_interview')
True
반응형