Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

[1.0.X] Fixed #9804 -- Corrected the introspection of sequence names.…

… This was causing problems when flushing tables that had many-to-many relations through an inherited table. Thanks to jdimov for the report.

Merge of r10552 from trunk.


git-svn-id: http://code.djangoproject.com/svn/django/branches/releases/1.0.X@10553 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 6be2d903f328421e11a0da3c3321d15ceaeb1656 1 parent 2c6e3b3
Russell Keith-Magee authored April 13, 2009
5  django/contrib/contenttypes/generic.py
@@ -193,9 +193,9 @@ def __get__(self, instance, instance_type=None):
193 193
         rel_model = self.field.rel.to
194 194
         superclass = rel_model._default_manager.__class__
195 195
         RelatedManager = create_generic_related_manager(superclass)
196  
-        
  196
+
197 197
         qn = connection.ops.quote_name
198  
-                
  198
+
199 199
         manager = RelatedManager(
200 200
             model = rel_model,
201 201
             instance = instance,
@@ -285,6 +285,7 @@ def __init__(self, to, related_name=None, limit_choices_to=None, symmetrical=Tru
285 285
         self.limit_choices_to = limit_choices_to or {}
286 286
         self.symmetrical = symmetrical
287 287
         self.multiple = True
  288
+        self.through = None
288 289
 
289 290
 class BaseGenericInlineFormSet(BaseModelFormSet):
290 291
     """
5  django/db/backends/__init__.py
@@ -440,7 +440,10 @@ def sequence_list(self):
440 440
                         break # Only one AutoField is allowed per model, so don't bother continuing.
441 441
 
442 442
                 for f in model._meta.local_many_to_many:
443  
-                    sequence_list.append({'table': f.m2m_db_table(), 'column': None})
  443
+                    # If this is an m2m using an intermediate table,
  444
+                    # we don't need to reset the sequence.
  445
+                    if f.rel.through is None:
  446
+                        sequence_list.append({'table': f.m2m_db_table(), 'column': None})
444 447
 
445 448
         return sequence_list
446 449
 
20  tests/regressiontests/m2m_through_regress/models.py
@@ -35,6 +35,22 @@ class Group(models.Model):
35 35
     def __unicode__(self):
36 36
         return self.name
37 37
 
  38
+# A set of models that use an non-abstract inherited model as the 'through' model.
  39
+class A(models.Model):
  40
+    a_text = models.CharField(max_length=20)
  41
+
  42
+class ThroughBase(models.Model):
  43
+    a = models.ForeignKey(A)
  44
+    b = models.ForeignKey('B')
  45
+
  46
+class Through(ThroughBase):
  47
+    extra = models.CharField(max_length=20)
  48
+
  49
+class B(models.Model):
  50
+    b_text = models.CharField(max_length=20)
  51
+    a_list = models.ManyToManyField(A, through=Through)
  52
+
  53
+
38 54
 __test__ = {'API_TESTS':"""
39 55
 # Create some dummy data
40 56
 >>> bob = Person.objects.create(name='Bob')
@@ -176,4 +192,8 @@ def __unicode__(self):
176 192
 >>> bob.group_set.filter(membership__price=50)
177 193
 [<Group: Roll>]
178 194
 
  195
+## Regression test for #9804
  196
+# Flush the database, just to make sure we can.
  197
+>>> management.call_command('flush', verbosity=0, interactive=False)
  198
+
179 199
 """}

0 notes on commit 6be2d90

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