| 8번째 줄: |
8번째 줄: |
| | class Profile(models.Model): | | class Profile(models.Model): |
| | user = models.OneToOneField(settings.AUTH_USER_MODEL, on_delete=models.CASCADE) | | user = models.OneToOneField(settings.AUTH_USER_MODEL, on_delete=models.CASCADE) |
| − | </syntaxhighlight>일반적인 프로필 모델이라면 위 과정만으로도 구현이 끝난다. | + | </syntaxhighlight> |
| | + | |
| | + | = 더 나아가기 = |
| | + | 일반적인 프로필 모델이라면 위 과정만으로도 구현이 끝난다. |
| | | | |
| | 다만, 이번엔 여러 계정을 하나의 프로필에 엮어줄 예정이라, AbstractBaseUser를 이용하여 다음과 같은 방식으로 짜주자. 다음 문서를 참고하자. <syntaxhighlight lang="python"> | | 다만, 이번엔 여러 계정을 하나의 프로필에 엮어줄 예정이라, AbstractBaseUser를 이용하여 다음과 같은 방식으로 짜주자. 다음 문서를 참고하자. <syntaxhighlight lang="python"> |
| − | class User(AbstractBaseUser): # 사용자들..!! | + | class User(AbstractBaseUser): |
| − | # 계정관련
| + | identifier = models.CharField(max_length=20, unique=True) |
| − | identifier = models.CharField(max_length=20, unique=True, null=True, blank=False) # 로그인 할 때 사용할 식별자. | + | is_active = models.BooleanField(default=True) |
| − | email = models.EmailField(max_length=60) | + | 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) # 연결할 프로필모델. 아래에서 정의. |
| | # 프로필이 사라지면 사용자 모델도 한꺼번에 다 없어지게끔! | | # 프로필이 사라지면 사용자 모델도 한꺼번에 다 없어지게끔! |
| | + | objects = UserManager() # 회원가입을 다룰 클래스를 지정한다. |
| | | | |
| − | # 유저권한 관련
| + | USERNAME_FIELD = 'identifier' # 식별자로 사용할 필드. |
| − | is_active = models.BooleanField(default=True) # 장고 필수필드. 이게 false면 로그인 자체가 안됨.
| + | REQUIRED_FIELDS = [] # 회원가입 때 필수 입력필드. |
| − | is_staff = models.BooleanField(default=False)
| |
| − | is_admin = models.BooleanField(default=False) # 장고 필수필드
| |
| − | is_superuser = models.BooleanField(default=False)
| |
| − | | |
| − | USERNAME_FIELD = 'identifier' # 어떤 것을 로그인 때의 식별자로 사용할 것인가. | |
| − | REQUIRED_FIELDS = ['email', ] # 입력할 때 필수입력 필드 지정. | |
| | | | |
| | def __str__(self): | | def __str__(self): |
| − | return self.email#self.nickname +'.' +self.identifier | + | return self.identifier |
| − | def has_perm(self, perm, obj=None): # 이건 뭐람;;?
| + | </syntaxhighlight>그리고 프로필 계정은 필요에 따라 다음과 같이 짠다. User에서 참고해야 하므로 User모델보다 위에 위치하게 해주자.<syntaxhighlight lang="python"> |
| − | return self.is_admin
| |
| − | def has_module_perms(self, app_label):
| |
| − | return True
| |
| − | | |
| − | objects = AccountManager() # 회원가입을 다루는 클래스.
| |
| − | </syntaxhighlight>그리고 프로필 계정은 필요에 따라 다음과 같이 짠다.<syntaxhighlight lang="python"> | |
| | class Profile(models.Model): | | class Profile(models.Model): |
| | '''계정모델에서 연결하여 상위에 있는, 하위 SNS계정을 종합하는 프로필.''' | | '''계정모델에서 연결하여 상위에 있는, 하위 SNS계정을 종합하는 프로필.''' |
| 55번째 줄: |
47번째 줄: |
| | <div class="alert alert-danger"> | | <div class="alert alert-danger"> |
| | <h1><strong>프로필을 등록해야 글을 쓸 수 있습니다.</strong></h1> | | <h1><strong>프로필을 등록해야 글을 쓸 수 있습니다.</strong></h1> |
| − | <h2><a href="{% url 'membership:create_profile' %}">프로필 생성</a></h2> | + | <h2><a href="{% url 'account:create_profile' %}">프로필 생성</a></h2> |
| | </div> | | </div> |
| | {% endif %} | | {% endif %} |