﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
26729	TabularInline not respecting form's custom label and help text if set in form's __init__ method	nrogers64	Paulo	"Here is my models.py file:

{{{
#!python
from django.db import models


class Author(models.Model):
    name = models.CharField(max_length=100)

    class Meta:
        ordering = ('name',)

    def __unicode__(self):
        return self.name


class Book(models.Model):
    author = models.ForeignKey(Author, on_delete=models.CASCADE)
    title = models.CharField(max_length=100, help_text='The book\'s title.')

    class Meta:
        ordering = ('title',)

    def __unicode__(self):
        return self.title
}}}

Here is my forms.py file:

{{{
#!python
from django import forms

from .models import Book


class BookForm1(forms.ModelForm):
    title = forms.CharField(label='Foo', help_text='Bar')

    class Meta:
        model = Book
        fields = [
            'title',
        ]


class BookForm2(forms.ModelForm):
    class Meta:
        model = Book
        fields = [
            'title',
        ]

    def __init__(self, *args, **kwargs):
        super(BookForm2, self).__init__(*args, **kwargs)

        self.fields['title'].label = 'Baz'
        self.fields['title'].help_text = 'Qux'
}}}

Here is my admin.py file:

{{{
#!python
from django.contrib import admin

from .forms import BookForm1
from .models import Author, Book


class BookInline(admin.TabularInline):
    model = Book
    form = BookForm1


class AuthorAdmin(admin.ModelAdmin):
    inlines = [
        BookInline,
    ]

admin.site.register(Author, AuthorAdmin)
admin.site.register(Book)
}}}

Using the above code, if I go to /admin/name_of_app/author/add/ it works as expected, meaning that the field for the books is labeled ""Foo"" and its help text says ""Bar"". However, if I edit admin.py and replace both instances of `BookForm1` with `BookForm2`, the field for the books is labeled ""Title"" and its help text says ""The book's title."". In other words, it is falling back to the title and help text provided by the model instead of using what's defined in the `BookForm2` class' `__init__` method. I should also note that if I replace `admin.TabularInline` with `admin.StackedInline` then both `BookForm1` and `BookForm2` work as expected."	Bug	closed	contrib.admin	1.9	Normal	fixed		commonzenpython@…	Accepted	1	0	0	0	0	0
