summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRussell Keith-Magee <russell@keith-magee.com>2010-04-27 12:35:49 +0000
committerRussell Keith-Magee <russell@keith-magee.com>2010-04-27 12:35:49 +0000
commit2f9eef1227aa5d10c57995a5363696e8adc276b6 (patch)
tree979425404368ddef8285f6759b7fcfca5dc75f36
parentffe79b097905fac4be83e30ab4de3cab98fbc723 (diff)
Fixed #13407 -- Corrected verbose names for autogenerated m2m models, and cleaned up the default form prefix when an autogenerated m2m through model is used in a formset. Thanks to carljm for the report.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@13029 bcc190cf-cafb-0310-a4f2-bffc1f526a37
-rw-r--r--django/db/models/fields/related.py4
-rw-r--r--django/forms/models.py2
-rw-r--r--tests/regressiontests/admin_inlines/models.py14
-rw-r--r--tests/regressiontests/admin_inlines/tests.py10
4 files changed, 28 insertions, 2 deletions
diff --git a/django/db/models/fields/related.py b/django/db/models/fields/related.py
index 1e016fa7e1..c6fcdac845 100644
--- a/django/db/models/fields/related.py
+++ b/django/db/models/fields/related.py
@@ -969,7 +969,9 @@ def create_many_to_many_intermediary_model(field, klass):
'managed': managed,
'auto_created': klass,
'app_label': klass._meta.app_label,
- 'unique_together': (from_, to)
+ 'unique_together': (from_, to),
+ 'verbose_name': _('%(from)s-%(to)s relationship') % {'from': from_, 'to': to},
+ 'verbose_name_plural': _('%(from)s-%(to)s relationships') % {'from': from_, 'to': to},
})
# Construct and return the new class.
return type(name, (models.Model,), {
diff --git a/django/forms/models.py b/django/forms/models.py
index 42de898aa7..4ac3f950ba 100644
--- a/django/forms/models.py
+++ b/django/forms/models.py
@@ -718,7 +718,7 @@ class BaseInlineFormSet(BaseModelFormSet):
#@classmethod
def get_default_prefix(cls):
from django.db.models.fields.related import RelatedObject
- return RelatedObject(cls.fk.rel.to, cls.model, cls.fk).get_accessor_name()
+ return RelatedObject(cls.fk.rel.to, cls.model, cls.fk).get_accessor_name().replace('+','')
get_default_prefix = classmethod(get_default_prefix)
def save_new(self, form, commit=True):
diff --git a/tests/regressiontests/admin_inlines/models.py b/tests/regressiontests/admin_inlines/models.py
index 2c6a64dc7a..bca582b9ab 100644
--- a/tests/regressiontests/admin_inlines/models.py
+++ b/tests/regressiontests/admin_inlines/models.py
@@ -30,6 +30,20 @@ class Child(models.Model):
def __unicode__(self):
return u'I am %s, a child of %s' % (self.name, self.parent)
+class Book(models.Model):
+ name = models.CharField(max_length=50)
+
+class Author(models.Model):
+ name = models.CharField(max_length=50)
+ books = models.ManyToManyField(Book)
+
+class BookInline(admin.TabularInline):
+ model = Author.books.through
+
+class AuthorAdmin(admin.ModelAdmin):
+ inlines = [BookInline]
+
+admin.site.register(Author, AuthorAdmin)
class Holder(models.Model):
dummy = models.IntegerField()
diff --git a/tests/regressiontests/admin_inlines/tests.py b/tests/regressiontests/admin_inlines/tests.py
index 1ac0100b4a..ffcbe1e4ba 100644
--- a/tests/regressiontests/admin_inlines/tests.py
+++ b/tests/regressiontests/admin_inlines/tests.py
@@ -38,6 +38,16 @@ class TestInline(TestCase):
% holder.id)
self.assertContains(response, '<label>Inner readonly label:</label>')
+ def test_many_to_many_inlines(self):
+ "Autogenerated many-to-many inlines are displayed correctly (#13407)"
+ response = self.client.get('/test_admin/admin/admin_inlines/author/add/')
+ # The heading for the m2m inline block uses the right text
+ self.assertContains(response, '<h2>Author-book relationships</h2>')
+ # The "add another" label is correct
+ self.assertContains(response, 'Add another Author-Book Relationship')
+ # The '+' is dropped from the autogenerated form prefix (Author_books+)
+ self.assertContains(response, 'id="id_Author_books-TOTAL_FORMS"')
+
class TestInlineMedia(TestCase):
fixtures = ['admin-views-users.xml']