Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

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
  • Loading branch information...
commit 2f9eef1227aa5d10c57995a5363696e8adc276b6 1 parent ffe79b0
Russell Keith-Magee freakboy3742 authored
4 django/db/models/fields/related.py
View
@@ -969,7 +969,9 @@ def set_managed(field, model, cls):
'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,), {
2  django/forms/models.py
View
@@ -718,7 +718,7 @@ def _construct_form(self, i, **kwargs):
#@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):
14 tests/regressiontests/admin_inlines/models.py
View
@@ -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()
10 tests/regressiontests/admin_inlines/tests.py
View
@@ -38,6 +38,16 @@ def test_readonly_stacked_inline_label(self):
% 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']
Please sign in to comment.
Something went wrong with that request. Please try again.