| 20번째 줄: |
20번째 줄: |
| | identifier = models.CharField(max_length=20, unique=True) | | identifier = models.CharField(max_length=20, unique=True) |
| | is_active = models.BooleanField(default=True) | | is_active = models.BooleanField(default=True) |
| | + | is_staff = models.BooleanField(default=False) |
| | is_admin = models.BooleanField(default=False) | | is_admin = models.BooleanField(default=False) |
| | profile = models.ForeignKey(Profile, on_delete=models.CASCADE, null=True, blank=True) # 연결할 프로필모델. 아래에서 정의. | | profile = models.ForeignKey(Profile, on_delete=models.CASCADE, null=True, blank=True) # 연결할 프로필모델. 아래에서 정의. |
| 30번째 줄: |
31번째 줄: |
| | def __str__(self): | | def __str__(self): |
| | return self.identifier | | return self.identifier |
| | + | |
| | + | def has_module_perms(self, app_label): |
| | + | '''앱 라벨을 받아, 해당 앱에 접근 가능한지 파악''' |
| | + | return True |
| | + | def has_perm(self, perm, obj=None): |
| | + | '''권한 소지여부를 판단하기 위한 메서드''' |
| | + | return True |
| | </syntaxhighlight>그리고 프로필 계정은 필요에 따라 다음과 같이 짠다. User에서 참고해야 하므로 User모델보다 위에 위치하게 해주자.<syntaxhighlight lang="python"> | | </syntaxhighlight>그리고 프로필 계정은 필요에 따라 다음과 같이 짠다. User에서 참고해야 하므로 User모델보다 위에 위치하게 해주자.<syntaxhighlight lang="python"> |
| | class Profile(models.Model): | | class Profile(models.Model): |
| 40번째 줄: |
48번째 줄: |
| | email_active = models.BooleanField(default=False) # 이메일 검증여부 | | email_active = models.BooleanField(default=False) # 이메일 검증여부 |
| | </syntaxhighlight>이렇게 하면 user.profile.username 같은 방식으로 프로필 속성에 접근할 수 있다. | | </syntaxhighlight>이렇게 하면 user.profile.username 같은 방식으로 프로필 속성에 접근할 수 있다. |
| | + | |
| | + | 이후 admin.py 등을 작성하고 관리자 계정 작성 및 로그인 하여 잘 작성되었는지 확인한다. |
| | + | |
| | + | === admin.py === |
| | + | <syntaxhighlight lang="python"> |
| | + | from django.contrib import admin |
| | + | from .models import User, Profile # 직접 등록한 모델 |
| | + | |
| | + | @admin.register(User) |
| | + | class UserAdmin(admin.ModelAdmin): |
| | + | list_display = ('identifier',) |
| | + | exclude = ('password',) # 사용자 상세 정보에서 비밀번호 필드를 노출하지 않음 |
| | + | |
| | + | @admin.register(Profile) |
| | + | class UserAdmin(admin.ModelAdmin): |
| | + | list_display = ('nickname',) |
| | + | </syntaxhighlight> |
| | | | |
| | == 계정에서 프로필 생성 == | | == 계정에서 프로필 생성 == |