Commits

shaib committed 8c9d655

Add child class as parameter in helper methods for generic db subclasses
to allow the subclasses to be subclassed in turn.

Comments (0)

Files changed (3)

south/db/generic.py

         MockModel._meta.model = MockModel
         return MockModel
 
-    def _db_positive_type_for_alter_column(self, field):
+    def _db_positive_type_for_alter_column(self, klass, field):
         """
         A helper for subclasses overriding _db_type_for_alter_column:
         Remove the check constraint from the type string for PositiveInteger
         and PositiveSmallInteger fields.
+        @param klass: The type of the child (required to allow this to be used when it is subclassed)
         @param field: The field to generate type for
         """
-        super_result = super(type(self), self)._db_type_for_alter_column(field)
+        super_result = super(klass, self)._db_type_for_alter_column(field)
         if isinstance(field, (models.PositiveSmallIntegerField, models.PositiveIntegerField)):
             return super_result.split(" ", 1)[0]
         return super_result
         
-    def _alter_add_positive_check(self, field, name, params, sqls):
+    def _alter_add_positive_check(self, klass, field, name, params, sqls):
         """
         A helper for subclasses overriding _alter_add_column_mods:
         Add a check constraint verifying positivity to PositiveInteger and
         PositiveSmallInteger fields.
         """
-        super(type(self), self)._alter_add_column_mods(field, name, params, sqls)
+        super(klass, self)._alter_add_column_mods(field, name, params, sqls)
         if isinstance(field, (models.PositiveSmallIntegerField, models.PositiveIntegerField)):
             uniq_hash = abs(hash(tuple(params.values())))
             d = dict(

south/db/postgresql_psycopg2.py

         "Rename an index individually"
         generic.DatabaseOperations.rename_table(self, old_index_name, index_name)
 
-    _db_type_for_alter_column = generic.alias("_db_positive_type_for_alter_column")
-    _alter_add_column_mods = generic.alias("_alter_add_positive_check")
+    def _db_type_for_alter_column(self, field): 
+        return self._db_positive_type_for_alter_column(DatabaseOperations, field)
+
+    def _alter_add_column_mods(self, field, name, params, sqls):
+        return self._alter_add_positive_check(DatabaseOperations, field, name, params, sqls)

south/db/sql_server/pyodbc.py

         params = (self.quote_name(old_table_name), self.quote_name(table_name))
         self.execute('EXEC sp_rename %s, %s' % params)
 
-    _db_type_for_alter_column = generic.alias("_db_positive_type_for_alter_column")
-    _alter_add_column_mods = generic.alias("_alter_add_positive_check")
+    def _db_type_for_alter_column(self, field): 
+        return self._db_positive_type_for_alter_column(DatabaseOperations, field)
+
+    def _alter_add_column_mods(self, field, name, params, sqls):
+        return self._alter_add_positive_check(DatabaseOperations, field, name, params, sqls)
 
     @invalidate_table_constraints
     def delete_foreign_key(self, table_name, column):