Ticket #5014: 5014-with-tests.diff

File 5014-with-tests.diff, 2.6 KB (added by Claude Paroz, 13 years ago)

Updated/completed patch with tests

  • django/core/management/commands/inspectdb.py

    diff --git a/django/core/management/commands/inspectdb.py b/django/core/management/commands/inspectdb.py
    index 5f0e278..e6d142b 100644
    a b class Command(NoArgsCommand):  
    151151            field_params['max_length'] = row[3]
    152152
    153153        if field_type == 'DecimalField':
    154             field_params['max_digits'] = row[4]
    155             field_params['decimal_places'] = row[5]
     154            if not row[4] or not row[5]:
     155                field_notes.append('''max_digits and decimal_places have been guessed, as this database handles decimal fields as float''')
     156                max_digits, decimal_places = 10, 5
     157            else:
     158                max_digits, decimal_places = row[4], row[5]
     159            field_params['max_digits'] = max_digits
     160            field_params['decimal_places'] = decimal_places
    156161
    157162        return field_type, field_params, field_notes
    158163
  • django/db/backends/sqlite3/introspection.py

    diff --git a/django/db/backends/sqlite3/introspection.py b/django/db/backends/sqlite3/introspection.py
    index 5ee7b64..d34a06b 100644
    a b class FlexibleFieldLookupDict(object):  
    2020        'integer unsigned': 'PositiveIntegerField',
    2121        'decimal': 'DecimalField',
    2222        'real': 'FloatField',
     23        'numeric': 'FloatField',
    2324        'text': 'TextField',
    2425        'char': 'CharField',
    2526        'date': 'DateField',
  • tests/regressiontests/inspectdb/models.py

    diff --git a/tests/regressiontests/inspectdb/models.py b/tests/regressiontests/inspectdb/models.py
    index fc2548b..0111cc5 100644
    a b class People(models.Model):  
    66
    77class Message(models.Model):
    88    from_field = models.ForeignKey(People, db_column='from_id')
     9
     10class DecimalTest(models.Model):
     11    dec_field = models.DecimalField(max_digits=10, decimal_places=5)
  • tests/regressiontests/inspectdb/tests.py

    diff --git a/tests/regressiontests/inspectdb/tests.py b/tests/regressiontests/inspectdb/tests.py
    index 683e6e9..5b5cf39 100644
    a b class InspectDBTestCase(TestCase):  
    1414        self.assertNotIn("from = models.ForeignKey(InspectdbPeople)", out.getvalue(), msg=error_message)
    1515        self.assertIn("from_field = models.ForeignKey(InspectdbPeople)", out.getvalue())
    1616        out.close()
     17
     18    def test_decimal_field(self):
     19        out = StringIO()
     20        call_command('inspectdb', stdout=out)
     21        self.assertIn("dec_field = models.DecimalField(max_digits=10, decimal_places=5)", out.getvalue())
Back to Top