在我的 UserProfile 模型中,我只是在此处添加了 django-imagekit 和 thumbnail 字段来为我创建缩略图,但是当我运行 ./manage.py makemigrations 时,django 说没有检测到任何更改,并且 thumbnail 字段没有添加到数据库。
这是我的代码。我正在使用 Python 3.4 和 Django 1.7:
from django.db import models
from django.contrib.auth.models import User
from imagekit.models import ImageSpecField
from imagekit.processors import ResizeToFill
from phonenumber_field.modelfields import PhoneNumberField
def get_upload_file_name(instance, filename):
return '/'.join([instance.user_auth.email, filename])
# Create your models here.
class UserProfile(models.Model):
user_auth = models.OneToOneField(User, related_name="profile")
phone = PhoneNumberField(null=True, blank=True, verbose_name="Phone number")
birth_date = models.DateField(verbose_name="Date of Birth", null=True, blank=True)
GENDER_CHOICES = (
('M', 'Male'),
('F', 'Female'),
('N', 'Not Specified'),
)
gender = models.CharField(
max_length=1, choices=GENDER_CHOICES, blank=False, default='N', verbose_name='Gender')
pic = models.ImageField(upload_to=get_upload_file_name,
width_field="width_field",
height_field="height_field",
null=True,
blank=True,
verbose_name="Profile Picture"
)
height_field = models.PositiveIntegerField(null=True, default=0)
width_field = models.PositiveIntegerField(null=True, default=0)
thumbnail = ImageSpecField(source='pic',
processors=[ResizeToFill(120,120)],
format='JPEG',
options={'quality': 60})