Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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
  • Loading branch information...
commit c1a16d54b0fce2ffe89eab9a69e689f87a4c1ddc 1 parent cd34c16
Adrian Holovaty authored
1  django/core/db/backends/mysql.py
@@ -133,7 +133,6 @@ def get_relations(cursor, table_name):
133 133
     'TimeField':         'time',
134 134
     'URLField':          'varchar(200)',
135 135
     'USStateField':      'varchar(2)',
136  
-    'XMLField':          'longtext',
137 136
 }
138 137
 
139 138
 DATA_TYPES_REVERSE = {
1  django/core/db/backends/postgresql.py
@@ -170,7 +170,6 @@ def get_relations(cursor, table_name):
170 170
     'TimeField':         'time',
171 171
     'URLField':          'varchar(200)',
172 172
     'USStateField':      'varchar(2)',
173  
-    'XMLField':          'text',
174 173
 }
175 174
 
176 175
 # Maps type codes to Django Field types.
1  django/core/db/backends/sqlite3.py
@@ -170,7 +170,6 @@ def get_relations(cursor, table_name):
170 170
     'TimeField':                    'time',
171 171
     'URLField':                     'varchar(200)',
172 172
     'USStateField':                 'varchar(2)',
173  
-    'XMLField':                     'text',
174 173
 }
175 174
 
176 175
 DATA_TYPES_REVERSE = {}
6  django/core/management.py
@@ -47,7 +47,7 @@ def _is_valid_dir_name(s):
47 47
 # If the foreign key points to an AutoField, the foreign key should be an
48 48
 # IntegerField, not an AutoField. Otherwise, the foreign key should be the same
49 49
 # type of field as the field to which it points.
50  
-get_rel_data_type = lambda f: (f.__class__.__name__ == 'AutoField') and 'IntegerField' or f.__class__.__name__
  50
+get_rel_data_type = lambda f: (f.get_internal_type() == 'AutoField') and 'IntegerField' or f.get_internal_type()
51 51
 
52 52
 def get_sql_create(mod):
53 53
     "Returns a list of the CREATE TABLE SQL statements for the given module."
@@ -62,7 +62,7 @@ def get_sql_create(mod):
62 62
                 data_type = get_rel_data_type(rel_field)
63 63
             else:
64 64
                 rel_field = f
65  
-                data_type = f.__class__.__name__
  65
+                data_type = f.get_internal_type()
66 66
             col_type = db.DATA_TYPES[data_type]
67 67
             if col_type is not None:
68 68
                 field_output = [f.column, col_type % rel_field.__dict__]
@@ -634,7 +634,7 @@ def createcachetable(tablename):
634 634
     table_output = []
635 635
     index_output = []
636 636
     for f in fields:
637  
-        field_output = [f.column, db.DATA_TYPES[f.__class__.__name__] % f.__dict__]
  637
+        field_output = [f.column, db.DATA_TYPES[f.get_internal_type()] % f.__dict__]
638 638
         field_output.append("%sNULL" % (not f.null and "NOT " or ""))
639 639
         if f.unique:
640 640
             field_output.append("UNIQUE")
8  django/core/meta/fields.py
@@ -114,6 +114,9 @@ def get_db_column(self):
114 114
     def get_cache_name(self):
115 115
         return '_%s_cache' % self.name
116 116
 
  117
+    def get_internal_type(self):
  118
+        return self.__class__.__name__
  119
+
117 120
     def pre_save(self, value, add):
118 121
         "Returns field's value just before saving."
119 122
         return value
@@ -552,11 +555,14 @@ class USStateField(Field):
552 555
     def get_manipulator_field_objs(self):
553 556
         return [formfields.USStateField]
554 557
 
555  
-class XMLField(Field):
  558
+class XMLField(TextField):
556 559
     def __init__(self, verbose_name=None, name=None, schema_path=None, **kwargs):
557 560
         self.schema_path = schema_path
558 561
         Field.__init__(self, verbose_name, name, **kwargs)
559 562
 
  563
+    def get_internal_type(self):
  564
+        return "TextField"
  565
+
560 566
     def get_manipulator_field_objs(self):
561 567
         return [curry(formfields.XMLLargeTextField, schema_path=self.schema_path)]
562 568
 

0 notes on commit c1a16d5

Please sign in to comment.
Something went wrong with that request. Please try again.