#26729: TabularInline not respecting form's custom label and help text if set in form's __init__ method -------------------------------+-------------------- Reporter: nrogers64 | Owner: nobody Type: Bug | Status: new Component: Uncategorized | Version: 1.9 Severity: Normal | Keywords: Triage Stage: Unreviewed | Has patch: 0 Easy pickings: 0 | UI/UX: 0 -------------------------------+-------------------- 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. -- Ticket URL: <https://code.djangoproject.com/ticket/26729> Django <https://code.djangoproject.com/> The Web framework for perfectionists with deadlines. -- You received this message because you are subscribed to the Google Groups "Django updates" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-updates+unsubscr...@googlegroups.com. To post to this group, send email to django-updates@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/django-updates/052.f1dc075e380646b57dd93014b77234c1%40djangoproject.com. For more options, visit https://groups.google.com/d/optout.