我只是扩展了我的用户模型,添加了用户、照片、电话、电子邮件等字段。当我使用“./manage.py makemigrations”命令在控制台中进行迁移时,我的问题出现了。完整的消息是:
ValueError: Could not find function url in dracoin.apps.home.models.
Please note that due to Python 2 limitations, you cannot serialize unbound method functions (e.g. a method declared
and used in the same class body). Please move the function into the main module body to use migrations.
这是我的“models.py”(我相信这个 .py 是错误的根源):
from django.db import models
from django.contrib.auth.models import User
class userProfile(models.Model):
def url(self,filename):
ruta = "MultimediaData/Users/%s/%s"%(self.user.username,filename)
return ruta
user = models.OneToOneField(User)
photo = models.ImageField(upload_to=url)
phone = models.CharField(max_length=30)
email = models.EmailField(max_length=75)
def __unicode__(self):
return self.user.username
我是 django 和 python 的新手,如果我忽略了什么,请提前道歉。
谢谢!!