Ticket #29184: tabularinline_label_and_help_text_2.patch

File tabularinline_label_and_help_text_2.patch, 3.3 KB (added by David Sanders, 7 years ago)

Fixed patch

  • django/contrib/admin/helpers.py

    diff --git a/django/contrib/admin/helpers.py b/django/contrib/admin/helpers.py
    index ea6e0012dd..88895ce144 100644
    a b from django.utils.translation import gettext, gettext_lazy as _  
    1717ACTION_CHECKBOX_NAME = '_selected_action'
    1818
    1919
     20def get_field_label_and_help_text(form, field_name, model_admin):
     21    if form._meta.labels and field_name in form._meta.labels:
     22        label = form._meta.labels[field_name]
     23    else:
     24        label = label_for_field(field_name, form._meta.model, model_admin)
     25
     26    if form._meta.help_texts and field_name in form._meta.help_texts:
     27        help_text = form._meta.help_texts[field_name]
     28    else:
     29        help_text = help_text_for_field(field_name, form._meta.model)
     30
     31    return (label, help_text)
     32
     33
    2034class ActionForm(forms.Form):
    2135    action = forms.ChoiceField(label=_('Action:'))
    2236    select_across = forms.BooleanField(
    class AdminReadonlyField:  
    164178        else:
    165179            class_name = field
    166180
    167         if form._meta.labels and class_name in form._meta.labels:
    168             label = form._meta.labels[class_name]
    169         else:
    170             label = label_for_field(field, form._meta.model, model_admin)
    171 
    172         if form._meta.help_texts and class_name in form._meta.help_texts:
    173             help_text = form._meta.help_texts[class_name]
    174         else:
    175             help_text = help_text_for_field(class_name, form._meta.model)
     181        label, help_text = get_field_label_and_help_text(form, class_name, model_admin)
    176182
    177183        self.field = {
    178184            'name': class_name,
    class InlineAdminFormSet:  
    261267        for i, field_name in enumerate(flatten_fieldsets(self.fieldsets)):
    262268            if fk and fk.name == field_name:
    263269                continue
     270            form = self.formset.empty_form
    264271            if field_name in self.readonly_fields:
    265                 yield {
    266                     'label': label_for_field(field_name, self.opts.model, self.opts),
    267                     'widget': {'is_hidden': False},
    268                     'required': False,
    269                     'help_text': help_text_for_field(field_name, self.opts.model),
    270                 }
     272                label, help_text = get_field_label_and_help_text(form, field_name, self.opts)
     273                widget = {'is_hidden': False}
     274                required = False
    271275            else:
    272                 form_field = self.formset.empty_form.fields[field_name]
     276                form_field = form.fields[field_name]
    273277                label = form_field.label
    274278                if label is None:
    275279                    label = label_for_field(field_name, self.opts.model, self.opts)
    276                 yield {
    277                     'label': label,
    278                     'widget': form_field.widget,
    279                     'required': form_field.required,
    280                     'help_text': form_field.help_text,
    281                 }
     280                help_text = form_field.help_text
     281                widget = form_field.widget
     282                required = form_field.required
     283            yield {
     284                'label': label,
     285                'widget': widget,
     286                'required': required,
     287                'help_text': help_text,
     288            }
    282289
    283290    def inline_formset_data(self):
    284291        verbose_name = self.opts.verbose_name
Back to Top