Display name rather than id

This commit is contained in:
zandercymatics 2024-08-05 09:15:55 -06:00
parent a1c63a809d
commit 6a0412d872
No known key found for this signature in database
GPG key ID: FF4636ABEC9682B7
3 changed files with 10 additions and 2 deletions

View file

@ -192,6 +192,10 @@ class DomainSuborganizationForm(forms.ModelForm):
# Use the combobox rather than the regular select widget # Use the combobox rather than the regular select widget
self.fields["sub_organization"].widget.template_name = "django/forms/widgets/combobox.html" self.fields["sub_organization"].widget.template_name = "django/forms/widgets/combobox.html"
def get_suborganization_name(self):
"""Returns the suborganization name for the readonly view"""
return self.instance.sub_organization if self.instance else None
class BaseNameserverFormset(forms.BaseFormSet): class BaseNameserverFormset(forms.BaseFormSet):
def clean(self): def clean(self):

View file

@ -23,7 +23,7 @@
</form> </form>
{% else %} {% else %}
{% with description="The suborganization for this domain can only be updated by a organization administrator."%} {% with description="The suborganization for this domain can only be updated by a organization administrator."%}
{% include "includes/input_read_only.html" with field=form.sub_organization label_description=description%} {% include "includes/input_read_only.html" with field=form.sub_organization value=instance.get_suborganization_name label_description=description%}
{% endwith %} {% endwith %}
{% endif %} {% endif %}

View file

@ -7,4 +7,8 @@ Template include for read-only form fields
{% if label_description %} {% if label_description %}
<p class="usa-hint margin-top-0 margin-bottom-05">{{ label_description }}</p> <p class="usa-hint margin-top-0 margin-bottom-05">{{ label_description }}</p>
{% endif %} {% endif %}
<p class="read-only-value">{{ field.value }}</p> {% comment %}
This allows us to customize the displayed value.
For instance, Select fields will display the id by default.
{% endcomment %}
<p class="read-only-value">{{ value|default:field.value }}</p>