我只是扩展我的用户模型,添加像用户,照片,电话,电子邮件这样的字段。当我在控制台中使用"./manage.py e.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的新手,如果我忽略了一些事情,请提前道歉。
谢谢!!
发布于 2014-10-08 18:13:23
错误消息实际上告诉了您问题的所在-- url在photo字段的定义中是一个绑定方法,不能序列化--它甚至给出了解决方案,即将方法从类中移出主函数。这意味着:
def url(obj, filename):
ruta = "MultimediaData/Users/%s/%s"%(obj.user.username,filename)
return ruta
class userProfile(models.Model):
user = models.OneToOneField(User)
photo = models.ImageField(upload_to=url)https://stackoverflow.com/questions/26263356
复制相似问题