Ticket #8317: 8317_with_tests.diff

File 8317_with_tests.diff, 3.0 KB (added by David Gouldin, 13 years ago)
  • django/core/management/commands/inspectdb.py

    diff --git a/django/core/management/commands/inspectdb.py b/django/core/management/commands/inspectdb.py
    index 76073c7..76d2838 100644
    a b class Command(NoArgsCommand):  
    6262                if ' ' in att_name or '-' in att_name or keyword.iskeyword(att_name) or column_name != att_name:
    6363                    extra_params['db_column'] = column_name
    6464
     65                # Add primary_key and unique, if necessary.
     66                if column_name in indexes:
     67                    if indexes[column_name]['primary_key']:
     68                        extra_params['primary_key'] = True
     69                    elif indexes[column_name]['unique']:
     70                        extra_params['unique'] = True
     71
    6572                # Modify the field name to make it Python-compatible.
    6673                if ' ' in att_name:
    6774                    att_name = att_name.replace(' ', '_')
    class Command(NoArgsCommand):  
    8895                    extra_params.update(field_params)
    8996                    comment_notes.extend(field_notes)
    9097
    91                     # Add primary_key and unique, if necessary.
    92                     if column_name in indexes:
    93                         if indexes[column_name]['primary_key']:
    94                             extra_params['primary_key'] = True
    95                         elif indexes[column_name]['unique']:
    96                             extra_params['unique'] = True
    97 
    9898                    field_type += '('
    9999                   
    100100                if keyword.iskeyword(att_name):
  • tests/regressiontests/inspectdb/models.py

    diff --git a/tests/regressiontests/inspectdb/models.py b/tests/regressiontests/inspectdb/models.py
    index fc2548b..fac47aa 100644
    a b class People(models.Model):  
    66
    77class Message(models.Model):
    88    from_field = models.ForeignKey(People, db_column='from_id')
     9
     10class PeopleData(models.Model):
     11    people_pk = models.ForeignKey(People, primary_key=True)
     12    ssn = models.CharField(max_length=11)
     13
     14class PeopleMoreData(models.Model):
     15    people_unique = models.ForeignKey(People, unique=True)
     16    license = models.CharField(max_length=255)
     17
  • tests/regressiontests/inspectdb/tests.py

    diff --git a/tests/regressiontests/inspectdb/tests.py b/tests/regressiontests/inspectdb/tests.py
    index 683e6e9..e2eced5 100644
    a b class InspectDBTestCase(TestCase):  
    1313        error_message = "inspectdb generated an attribute name which is a python keyword"
    1414        self.assertNotIn("from = models.ForeignKey(InspectdbPeople)", out.getvalue(), msg=error_message)
    1515        self.assertIn("from_field = models.ForeignKey(InspectdbPeople)", out.getvalue())
     16        self.assertIn("people_pk = models.ForeignKey(InspectdbPeople, primary_key=True)",
     17            out.getvalue())
     18        self.assertIn("people_unique = models.ForeignKey(InspectdbPeople, unique=True)",
     19            out.getvalue())
    1620        out.close()
Back to Top