닉네임, 이미지, 메세지를 묶은 profileapp 만들기

account와 profile 1대1 매칭 시킬 것임
from django.contrib.auth.models import User
from django.db import models
# Create your models here.
class Profile(models.Model):
user = models.OneToOneField(User, on_delete=models.CASCADE, related_name='profiled')
image=models.ImageField(upload_to='profile/', null=True)
nickname = models.CharField(max_length=20, unique=True, null=True)
message = models.CharField(max_length = 100, null=True)
OneToOneField : 장고에서 제공하는 필드. profile과 user를 일대일 매칭
on_delete : 연결되어있는 유저 객체가 delete될때 profile객체는 어떻게 할지 결정. ex) cascade는 같이 삭제 함
related_name : view에서 여러 객체를 사용하는데 굳이 따로 profile객체를 찾지 않아도 request.user.profile.nickname과 같이 바로 접근해서 사용가능 함.
image=models.ImageField(upload_to='profile/', null=True)
upload_to : 이 이미지를 받아서 어디에 저장할지. ex) media_root밑에 profile경로가 추가되어 저장될 것임.
Accountapp에서는 기본제공되는 form을 사용
원래 방식대로 form을 만들려면


만든 model을 똑같이 form에서 비슷한 필드들을 만들어서 이것을 가져와서 써야함.
Mㄴodel Form : 기존에 있던 Model을 자동으로 form만들어줌

profileapp->forms.py 생성
from django.forms import ModelForm
from profileapp.models import Profile
class ProfileCreationForm(ModelForm):
class Meta:
model = Profile
fields = ['image','nickname','message']