diff options
| author | Russell Keith-Magee <russell@keith-magee.com> | 2010-02-22 14:04:13 +0000 |
|---|---|---|
| committer | Russell Keith-Magee <russell@keith-magee.com> | 2010-02-22 14:04:13 +0000 |
| commit | e6db084ac8fdf04ba20b5976a1cebfb77d55c97e (patch) | |
| tree | 71f65cecdc2ea74c94a3e1f6c3462d7f925c9357 /django | |
| parent | eb67e449dde298a35664c0daea61860ac63a1f58 (diff) | |
Fixed #11226 -- Corrected an validation edge case with m2m relations between two models with the same class name. Thanks to pkoch for the report, and to Ramiro Morales for the patch.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@12489 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'django')
| -rw-r--r-- | django/core/management/validation.py | 27 | ||||
| -rw-r--r-- | django/db/models/fields/related.py | 8 |
2 files changed, 18 insertions, 17 deletions
diff --git a/django/core/management/validation.py b/django/core/management/validation.py index 46cdfc5c46..9b65b8ed6c 100644 --- a/django/core/management/validation.py +++ b/django/core/management/validation.py @@ -179,19 +179,20 @@ def get_validation_errors(outfile, app=None): ) else: seen_intermediary_signatures.append(signature) - seen_related_fk, seen_this_fk = False, False - for field in f.rel.through._meta.fields: - if field.rel: - if not seen_related_fk and field.rel.to == f.rel.to: - seen_related_fk = True - elif field.rel.to == cls: - seen_this_fk = True - if not seen_related_fk or not seen_this_fk: - e.add(opts, "'%s' has a manually-defined m2m relation " - "through model %s, which does not have foreign keys " - "to %s and %s" % (f.name, f.rel.through._meta.object_name, - f.rel.to._meta.object_name, cls._meta.object_name) - ) + if not f.rel.through._meta.auto_created: + seen_related_fk, seen_this_fk = False, False + for field in f.rel.through._meta.fields: + if field.rel: + if not seen_related_fk and field.rel.to == f.rel.to: + seen_related_fk = True + elif field.rel.to == cls: + seen_this_fk = True + if not seen_related_fk or not seen_this_fk: + e.add(opts, "'%s' is a manually-defined m2m relation " + "through model %s, which does not have foreign keys " + "to %s and %s" % (f.name, f.rel.through._meta.object_name, + f.rel.to._meta.object_name, cls._meta.object_name) + ) elif isinstance(f.rel.through, basestring): e.add(opts, "'%s' specifies an m2m relation through model %s, " "which has not been installed" % (f.name, f.rel.through) diff --git a/django/db/models/fields/related.py b/django/db/models/fields/related.py index 5de6fb1067..a9d178a16c 100644 --- a/django/db/models/fields/related.py +++ b/django/db/models/fields/related.py @@ -511,7 +511,7 @@ def create_many_related_manager(superclass, rel=False): def _add_items(self, source_field_name, target_field_name, *objs): # join_table: name of the m2m link table # source_field_name: the PK fieldname in join_table for the source object - # target_col_name: the PK fieldname in join_table for the target object + # target_field_name: the PK fieldname in join_table for the target object # *objs - objects to add. Either object instances, or primary keys of object instances. # If there aren't any objects, there is nothing to do. @@ -914,7 +914,7 @@ def create_many_to_many_intermediary_model(field, klass): to_model = field.rel.to managed = klass._meta.managed or to_model._meta.managed name = '%s_%s' % (klass._meta.object_name, field.name) - if field.rel.to == RECURSIVE_RELATIONSHIP_CONSTANT or field.rel.to == klass._meta.object_name: + if field.rel.to == RECURSIVE_RELATIONSHIP_CONSTANT or to == klass._meta.object_name: from_ = 'from_%s' % to.lower() to = 'to_%s' % to.lower() else: @@ -973,7 +973,7 @@ class ManyToManyField(RelatedField, Field): connection.ops.max_name_length()) def _get_m2m_attr(self, related, attr): - "Function that can be curried to provide the source column name for the m2m table" + "Function that can be curried to provide the source accessor or DB column name for the m2m table" cache_attr = '_m2m_%s_cache' % attr if hasattr(self, cache_attr): return getattr(self, cache_attr) @@ -983,7 +983,7 @@ class ManyToManyField(RelatedField, Field): return getattr(self, cache_attr) def _get_m2m_reverse_attr(self, related, attr): - "Function that can be curried to provide the related column name for the m2m table" + "Function that can be curried to provide the related accessor or DB column name for the m2m table" cache_attr = '_m2m_reverse_%s_cache' % attr if hasattr(self, cache_attr): return getattr(self, cache_attr) |
