diff --git a/src/registrar/forms/domain.py b/src/registrar/forms/domain.py index ec370f268..55b6619d9 100644 --- a/src/registrar/forms/domain.py +++ b/src/registrar/forms/domain.py @@ -189,10 +189,6 @@ class DomainSuborganizationForm(forms.ModelForm): if self.instance and self.instance.sub_organization: self.fields["sub_organization"].widget.attrs["data-default-value"] = self.instance.sub_organization.pk - def get_suborganization_name(self): - """Returns the suborganization name for the readonly view""" - return self.instance.sub_organization.name if self.instance else None - class BaseNameserverFormset(forms.BaseFormSet): def clean(self): diff --git a/src/registrar/templates/domain_suborganization.html b/src/registrar/templates/domain_suborganization.html index c2e3431ad..a3b2231a7 100644 --- a/src/registrar/templates/domain_suborganization.html +++ b/src/registrar/templates/domain_suborganization.html @@ -25,7 +25,7 @@ {% else %} {% 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 value=instance.get_suborganization_name label_description=description%} + {% include "includes/input_read_only.html" with field=form.sub_organization value=suborganization_name label_description=description%} {% endwith %} {% endif %} {% endblock %} diff --git a/src/registrar/views/domain.py b/src/registrar/views/domain.py index 949d580bd..9b5f2e1c7 100644 --- a/src/registrar/views/domain.py +++ b/src/registrar/views/domain.py @@ -250,6 +250,13 @@ class DomainSubOrganizationView(DomainFormBaseView): context_object_name = "domain" form_class = DomainSuborganizationForm + def get_context_data(self, **kwargs): + """Adds custom context.""" + context = super().get_context_data(**kwargs) + if self.object and self.object.domain_info and self.object.domain_info.sub_organization: + context["suborganization_name"] = self.object.domain_info.sub_organization.name + return context + def get_form_kwargs(self, *args, **kwargs): """Add domain_info.organization_name instance to make a bound form.""" form_kwargs = super().get_form_kwargs(*args, **kwargs)