Commit 2f9eef12 authored by Russell Keith-Magee's avatar Russell Keith-Magee
Browse files

Fixed #13407 -- Corrected verbose names for autogenerated m2m models, and...

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
parent ffe79b09
Loading
Loading
Loading
Loading
+3 −1
Original line number Diff line number Diff line
@@ -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,), {
+1 −1
Original line number Diff line number Diff line
@@ -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):
+14 −0
Original line number Diff line number Diff line
@@ -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 −0
Original line number Diff line number Diff line
@@ -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']