我有以下型号。
from django.db import models
class Client(models.Model):
postcode = models.CharField(max_length=10)
first_name = models.CharField(max_length=100)
last_name = models.CharField(max_length=100)
address = models.TextField(blank=True)
phone = models.IntegerField(blank=True)
email = models.EmailField(blank=True)
url = models.URLField(blank=True)
client_since = models.DateTimeField('Client Since')
def __unicode__(self):
return self.first_name
def client_since(self):
return self.client_since.date() == datetime.date.today()
class Contractor(models.Model):
postcode = models.CharField(max_length=10)
first_name = models.CharField(max_length=100)
last_name = models.CharField(max_length=100)
address = models.TextField(blank=True)
phone = models.IntegerField(blank=True)
email = models.EmailField(blank=True)
contractor_since = models.DateTimeField('Contractor Since')
def __unicode__(self):
return self.first_name
def contractor_since(self):
return self.contractor_since.date() == datetime.date.today()
我运行'python manage.py validate'给我 - 找到0个错误
然后我运行'python manage.py sql“appname”然后我会看到我的表......
BEGIN;
CREATE TABLE "schedule_client" (
"id" integer NOT NULL PRIMARY KEY,
"postcode" varchar(10) NOT NULL,
"first_name" varchar(100) NOT NULL,
"last_name" varchar(100) NOT NULL,
"address" text NOT NULL,
"phone" integer NOT NULL,
"email" varchar(75) NOT NULL,
"url" varchar(200) NOT NULL,
"client_since" datetime NOT NULL
)
;
CREATE TABLE "schedule_contractor" (
"id" integer NOT NULL PRIMARY KEY,
"postcode" varchar(10) NOT NULL,
"first_name" varchar(100) NOT NULL,
"last_name" varchar(100) NOT NULL,
"address" text NOT NULL,
"phone" integer NOT NULL,
"email" varchar(75) NOT NULL
)
;
COMMIT;
但我没有在承包商表中看到“contracor_since ...正在创建数据库字段???我尝试了几次,我在OS X豹子上使用django 1.1.1。
我做错了什么?
答案 0 :(得分:4)
您正在使用相同的名称通过函数定义来遮蔽模型属性。尝试更改函数名称或模型属性(contractor_since
)。