<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array">
    <added>
      <filename>tests/modeltests/model_package/__init__.py</filename>
    </added>
    <added>
      <filename>tests/modeltests/model_package/models/__init__.py</filename>
    </added>
    <added>
      <filename>tests/modeltests/model_package/models/article.py</filename>
    </added>
    <added>
      <filename>tests/modeltests/model_package/models/publication.py</filename>
    </added>
    <added>
      <filename>tests/modeltests/model_package/tests.py</filename>
    </added>
  </added>
  <modified type="array">
    <modified>
      <diff>@@ -829,9 +829,18 @@ def create_many_to_many_intermediary_model(field, klass):
         'auto_created': klass,
         'unique_together': (from_, to)
     })
+    # If the models have been split into subpackages, klass.__module__
+    # will be the subpackge, not the models module for the app. (See #12168)
+    # Compose the actual models module name by stripping the trailing parts
+    # of the namespace until we find .models
+    parts = klass.__module__.split('.')
+    while parts[-1] != 'models':
+        parts.pop()
+    module = '.'.join(parts)
+    # Construct and return the new class.
     return type(name, (models.Model,), {
         'Meta': meta,
-        '__module__': klass.__module__,
+        '__module__': module,
         from_: models.ForeignKey(klass, related_name='%s+' % name),
         to: models.ForeignKey(to_model, related_name='%s+' % name)
     })</diff>
      <filename>django/db/models/fields/related.py</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>1b1dbbef722a8ba70cc2a64c5735daa5d0fab1e0</id>
    </parent>
  </parents>
  <author>
    <name>russellm</name>
    <email>russellm@bcc190cf-cafb-0310-a4f2-bffc1f526a37</email>
  </author>
  <url>http://github.com/django/django/commit/93705919d1178ee844aa45cfce3d7f29e6555beb</url>
  <id>93705919d1178ee844aa45cfce3d7f29e6555beb</id>
  <committed-date>2009-11-05T03:57:28-08:00</committed-date>
  <authored-date>2009-11-05T03:57:28-08:00</authored-date>
  <message>Fixed #12168 -- Corrected the registration of m2m autocreated models when models.py is split into submodules. Thanks to Jens Diemer for the report and test case.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@11724 bcc190cf-cafb-0310-a4f2-bffc1f526a37</message>
  <tree>f6c5050197281a38e4cc6ee279e6b80c39f276ca</tree>
  <committer>
    <name>russellm</name>
    <email>russellm@bcc190cf-cafb-0310-a4f2-bffc1f526a37</email>
  </committer>
</commit>
