Fixed #553 -- Added django.core.meta.fields.Field.get_internal_type() hook, for creating custom meta.Field subclasses. Thanks, wojtek3
git-svn-id: http://code.djangoproject.com/svn/django/trunk@713 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
cd34c163cc
commit
c1a16d54b0
|
@ -133,7 +133,6 @@ DATA_TYPES = {
|
||||||
'TimeField': 'time',
|
'TimeField': 'time',
|
||||||
'URLField': 'varchar(200)',
|
'URLField': 'varchar(200)',
|
||||||
'USStateField': 'varchar(2)',
|
'USStateField': 'varchar(2)',
|
||||||
'XMLField': 'longtext',
|
|
||||||
}
|
}
|
||||||
|
|
||||||
DATA_TYPES_REVERSE = {
|
DATA_TYPES_REVERSE = {
|
||||||
|
|
|
@ -170,7 +170,6 @@ DATA_TYPES = {
|
||||||
'TimeField': 'time',
|
'TimeField': 'time',
|
||||||
'URLField': 'varchar(200)',
|
'URLField': 'varchar(200)',
|
||||||
'USStateField': 'varchar(2)',
|
'USStateField': 'varchar(2)',
|
||||||
'XMLField': 'text',
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# Maps type codes to Django Field types.
|
# Maps type codes to Django Field types.
|
||||||
|
|
|
@ -170,7 +170,6 @@ DATA_TYPES = {
|
||||||
'TimeField': 'time',
|
'TimeField': 'time',
|
||||||
'URLField': 'varchar(200)',
|
'URLField': 'varchar(200)',
|
||||||
'USStateField': 'varchar(2)',
|
'USStateField': 'varchar(2)',
|
||||||
'XMLField': 'text',
|
|
||||||
}
|
}
|
||||||
|
|
||||||
DATA_TYPES_REVERSE = {}
|
DATA_TYPES_REVERSE = {}
|
||||||
|
|
|
@ -47,7 +47,7 @@ def _is_valid_dir_name(s):
|
||||||
# If the foreign key points to an AutoField, the foreign key should be an
|
# If the foreign key points to an AutoField, the foreign key should be an
|
||||||
# IntegerField, not an AutoField. Otherwise, the foreign key should be the same
|
# IntegerField, not an AutoField. Otherwise, the foreign key should be the same
|
||||||
# type of field as the field to which it points.
|
# type of field as the field to which it points.
|
||||||
get_rel_data_type = lambda f: (f.__class__.__name__ == 'AutoField') and 'IntegerField' or f.__class__.__name__
|
get_rel_data_type = lambda f: (f.get_internal_type() == 'AutoField') and 'IntegerField' or f.get_internal_type()
|
||||||
|
|
||||||
def get_sql_create(mod):
|
def get_sql_create(mod):
|
||||||
"Returns a list of the CREATE TABLE SQL statements for the given module."
|
"Returns a list of the CREATE TABLE SQL statements for the given module."
|
||||||
|
@ -62,7 +62,7 @@ def get_sql_create(mod):
|
||||||
data_type = get_rel_data_type(rel_field)
|
data_type = get_rel_data_type(rel_field)
|
||||||
else:
|
else:
|
||||||
rel_field = f
|
rel_field = f
|
||||||
data_type = f.__class__.__name__
|
data_type = f.get_internal_type()
|
||||||
col_type = db.DATA_TYPES[data_type]
|
col_type = db.DATA_TYPES[data_type]
|
||||||
if col_type is not None:
|
if col_type is not None:
|
||||||
field_output = [f.column, col_type % rel_field.__dict__]
|
field_output = [f.column, col_type % rel_field.__dict__]
|
||||||
|
@ -634,7 +634,7 @@ def createcachetable(tablename):
|
||||||
table_output = []
|
table_output = []
|
||||||
index_output = []
|
index_output = []
|
||||||
for f in fields:
|
for f in fields:
|
||||||
field_output = [f.column, db.DATA_TYPES[f.__class__.__name__] % f.__dict__]
|
field_output = [f.column, db.DATA_TYPES[f.get_internal_type()] % f.__dict__]
|
||||||
field_output.append("%sNULL" % (not f.null and "NOT " or ""))
|
field_output.append("%sNULL" % (not f.null and "NOT " or ""))
|
||||||
if f.unique:
|
if f.unique:
|
||||||
field_output.append("UNIQUE")
|
field_output.append("UNIQUE")
|
||||||
|
|
|
@ -114,6 +114,9 @@ class Field(object):
|
||||||
def get_cache_name(self):
|
def get_cache_name(self):
|
||||||
return '_%s_cache' % self.name
|
return '_%s_cache' % self.name
|
||||||
|
|
||||||
|
def get_internal_type(self):
|
||||||
|
return self.__class__.__name__
|
||||||
|
|
||||||
def pre_save(self, value, add):
|
def pre_save(self, value, add):
|
||||||
"Returns field's value just before saving."
|
"Returns field's value just before saving."
|
||||||
return value
|
return value
|
||||||
|
@ -552,11 +555,14 @@ class USStateField(Field):
|
||||||
def get_manipulator_field_objs(self):
|
def get_manipulator_field_objs(self):
|
||||||
return [formfields.USStateField]
|
return [formfields.USStateField]
|
||||||
|
|
||||||
class XMLField(Field):
|
class XMLField(TextField):
|
||||||
def __init__(self, verbose_name=None, name=None, schema_path=None, **kwargs):
|
def __init__(self, verbose_name=None, name=None, schema_path=None, **kwargs):
|
||||||
self.schema_path = schema_path
|
self.schema_path = schema_path
|
||||||
Field.__init__(self, verbose_name, name, **kwargs)
|
Field.__init__(self, verbose_name, name, **kwargs)
|
||||||
|
|
||||||
|
def get_internal_type(self):
|
||||||
|
return "TextField"
|
||||||
|
|
||||||
def get_manipulator_field_objs(self):
|
def get_manipulator_field_objs(self):
|
||||||
return [curry(formfields.XMLLargeTextField, schema_path=self.schema_path)]
|
return [curry(formfields.XMLLargeTextField, schema_path=self.schema_path)]
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue