Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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
  • Loading branch information...
commit 7b63d3d3b4fcf58070ced8e7a8c766cc93a26420 1 parent 77abadf
Russell Keith-Magee authored November 05, 2009
11  django/db/models/fields/related.py
@@ -829,9 +829,18 @@ def set_managed(field, model, cls):
1  tests/modeltests/model_package/__init__.py
... ...
@@ -0,0 +1 @@
  1
+
3  tests/modeltests/model_package/models/__init__.py
... ...
@@ -0,0 +1,3 @@
  1
+# Import all the models from subpackages
  2
+from article import Article
  3
+from publication import Publication
10  tests/modeltests/model_package/models/article.py
... ...
@@ -0,0 +1,10 @@
  1
+from django.db import models
  2
+from django.contrib.sites.models import Site
  3
+
  4
+class Article(models.Model):
  5
+    sites = models.ManyToManyField(Site)
  6
+    headline = models.CharField(max_length=100)
  7
+    publications = models.ManyToManyField("model_package.Publication", null=True, blank=True,)
  8
+
  9
+    class Meta:
  10
+        app_label = 'model_package'
7  tests/modeltests/model_package/models/publication.py
... ...
@@ -0,0 +1,7 @@
  1
+from django.db import models
  2
+
  3
+class Publication(models.Model):
  4
+    title = models.CharField(max_length=30)
  5
+
  6
+    class Meta:
  7
+        app_label = 'model_package'
34  tests/modeltests/model_package/tests.py
... ...
@@ -0,0 +1,34 @@
  1
+"""
  2
+>>> from models.publication import Publication
  3
+>>> from models.article import Article
  4
+>>> from django.contrib.auth.views import Site
  5
+
  6
+>>> p = Publication(title="FooBar")
  7
+>>> p.save()
  8
+>>> p
  9
+<Publication: Publication object>
  10
+
  11
+>>> from django.contrib.sites.models import Site
  12
+>>> current_site = Site.objects.get_current()
  13
+>>> current_site
  14
+<Site: example.com>
  15
+
  16
+# Regression for #12168: models split into subpackages still get M2M tables
  17
+
  18
+>>> a = Article(headline="a foo headline")
  19
+>>> a.save()
  20
+>>> a.publications.add(p)
  21
+>>> a.sites.add(current_site)
  22
+>>> a.save()
  23
+
  24
+>>> a = Article.objects.get(id=1)
  25
+>>> a
  26
+<Article: Article object>
  27
+>>> a.id
  28
+1
  29
+>>> a.sites.count()
  30
+1
  31
+
  32
+"""
  33
+
  34
+

0 notes on commit 7b63d3d

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