2
我只是擴展了我的用戶模型,添加了諸如用戶,照片,電話,電子郵件等字段。使用「./manage.py makemigrations」命令在控制檯中進行遷移時,會出現問題。完整的消息是:ValueError:在draco.apps.home.models中找不到函數url
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中,也蟒蛇,如果我忽略了某些事情,請提前道歉。
謝謝!
既然是一個類的方法,你應該做'upload_to = self.url' – karthikr 2014-10-08 18:10:51
@karthikr不正確的。 'self'沒有在該範圍內定義。 – 2014-10-08 18:11:49
Oopss。不知道我在想什麼 – karthikr 2014-10-08 18:25:20