Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fixed #12386 -- Corrected the column names produced for autogenerated…

… m2m tables when the related table is specified as a dot-separated string. Thanks to ldevesine for the report and simonb for the extra test case.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@12226 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 2b2db12032e47229a9d9af28b05a07648f3fef93 1 parent 373076a
Russell Keith-Magee freakboy3742 authored
2  django/db/models/fields/related.py
View
@@ -881,8 +881,8 @@ def create_many_to_many_intermediary_model(field, klass):
from django.db import models
managed = True
if isinstance(field.rel.to, basestring) and field.rel.to != RECURSIVE_RELATIONSHIP_CONSTANT:
- to = field.rel.to
to_model = field.rel.to
+ to = to_model.split('.')[-1]
def set_managed(field, model, cls):
field.rel.through._meta.managed = model._meta.managed or cls._meta.managed
add_lazy_relation(klass, field, to_model, set_managed)
25 tests/modeltests/model_package/tests.py
View
@@ -50,6 +50,31 @@ class Meta:
>>> ad.publications.count()
1
+# Regression for #12386 - field names on the autogenerated intermediate class
+# that are specified as dotted strings don't retain any path component for the
+# field or column name
+
+>>> Article.publications.through._meta.fields[1].name
+'article'
+
+>>> Article.publications.through._meta.fields[1].get_attname_column()
+('article_id', 'article_id')
+
+>>> Article.publications.through._meta.fields[2].name
+'publication'
+
+>>> Article.publications.through._meta.fields[2].get_attname_column()
+('publication_id', 'publication_id')
+
+>>> Article._meta.get_field('publications').m2m_db_table()
+'model_package_article_publications'
+
+>>> Article._meta.get_field('publications').m2m_column_name()
+'article_id'
+
+>>> Article._meta.get_field('publications').m2m_reverse_name()
+'publication_id'
+
"""}
Please sign in to comment.
Something went wrong with that request. Please try again.