我想扩展我的用户模型并添加头像(图像)字段。 我在models.py
中创建了新的应用帐户# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import models
from django.conf import settings
from django.contrib.auth.models import User
def download_location_of_usrpic(instance, filename):
return "%s/%s" %(instance.id, filename)
class Profile(models.Model):
user = models.OneToOneField(User, on_delete=models.CASCADE)
image = models.ImageField(
upload_to=download_location_of_usrpic,
null=True,
blank=True,
height_field="height_field",
width_field="width_field"
)
height_field = models.IntegerField(default=0)
width_field = models.IntegerField(default=0)
我的admin.py
from accounts.models import Profile
admin.site.register(Profile)
制作makemigrations并迁移
我也有GCBV
@method_decorator(login_required, name='dispatch')
class UserUpdateView(UpdateView):
model = User
fields = ('first_name', 'last_name', 'email', 'image', )
template_name = 'my_account.html'
success_url = reverse_lazy('my_account')
def get_object(self):
return self.request.user
但是我没有在管理员中看到这个字段并且在帐户中弄错了
Exception Value:
Unknown field(s) (image) specified for User
我错过了什么?