2017年11月5日 星期日

Django - User Model & Form

新增與django內建User model關聯的UserProfileInfo model

from __future__ import unicode_literals
from django.db import models
from django.contrib.auth.models import User
# Create your models here.

class UserProfileInfo(models.Model):

user = models.OneToOneField(User)

# additional
portfolio_site = models.URLField(blank=True)

profile_pic = models.ImageField(upload_to='profile_pics', blank=True)

def __str__(self):
return self.user.username
使用image前先安裝pillow Image Library

pip install pillow


設定form.py

設定views.py

設定urls.py

makemigrations


沒有留言:

張貼留言