我有以下名为 UnixTimestampField 的类:
from django.db import models
from datetime import datetime
from time import strftime
class UnixTimestampField(models.DateTimeField):
op_params=''
def __init__(self, null=False, blank=False, op_params='', **kwargs):
super(UnixTimestampField, self).__init__(**kwargs)
self.blank, self.isnull = blank, null
self.null = True
def db_type(self, connection):
typ=['TIMESTAMP']
# See above!
if self.isnull:
typ += ['NULL']
if self.op_params != '':
typ += [self.op_params]
return ' '.join(typ)
def to_python(self, value):
return datetime.from_timestamp(value)
def get_db_prep_value(self, value, connection, prepared=False):
if value==None:
return None
return strftime('%Y%m%d%H%M%S',value.timetuple())
def to_python(self, value):
return value
from south.modelsinspector import add_introspection_rules
add_introspection_rules([], ["^web\customfields\.unixtimestampfield\.UnixTimestampField"])
每次我运行以下命令时:python manage.py schemamigration web --initial
,我不断得到:
! (this field has class web.customfields.unixtimestampfield.UnixTimestampField)
有什么我想念的吗?它似乎甚至不承认该领域的存在?我正在阅读以下文档:
http://south.readthedocs.org/en/latest/customfields.html#extending-introspection
http://south.readthedocs.org/en/latest/tutorial/part4.html#keyword-arguments
[解决方案]
这个错误很简单。
以下行:
^web\customfields\.unixtimestampfield\.UnixTimestampField
不正确。
改为:
^web\.customfields\.unixtimestampfield\.UnixTimestampField