From 732cf2379b15ec83a7d13804587ef1bc79b56b44 Mon Sep 17 00:00:00 2001 From: CocoByte Date: Tue, 18 Jun 2024 11:56:19 -0600 Subject: [PATCH] move agency function to be inside Federal Agency model --- ...3_portfolio_domaininformation_portfolio_and_more.py | 6 +++--- src/registrar/models/federal_agency.py | 5 +++++ src/registrar/models/portfolio.py | 10 +++++----- 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/src/registrar/migrations/0103_portfolio_domaininformation_portfolio_and_more.py b/src/registrar/migrations/0103_portfolio_domaininformation_portfolio_and_more.py index df0945712..ac7a69074 100644 --- a/src/registrar/migrations/0103_portfolio_domaininformation_portfolio_and_more.py +++ b/src/registrar/migrations/0103_portfolio_domaininformation_portfolio_and_more.py @@ -1,9 +1,9 @@ -# Generated by Django 4.2.10 on 2024-06-18 03:19 +# Generated by Django 4.2.10 on 2024-06-18 17:55 from django.conf import settings from django.db import migrations, models import django.db.models.deletion -import registrar.models.portfolio +import registrar.models.federal_agency class Migration(migrations.Migration): @@ -136,7 +136,7 @@ class Migration(migrations.Migration): ( "federal_agency", models.ForeignKey( - default=registrar.models.portfolio.get_default_federal_agency, + default=registrar.models.federal_agency.FederalAgency.get_non_federal_agency, help_text="Associated federal agency", on_delete=django.db.models.deletion.PROTECT, to="registrar.federalagency", diff --git a/src/registrar/models/federal_agency.py b/src/registrar/models/federal_agency.py index cb09d12ac..521d5875a 100644 --- a/src/registrar/models/federal_agency.py +++ b/src/registrar/models/federal_agency.py @@ -230,3 +230,8 @@ class FederalAgency(TimeStampedModel): FederalAgency.objects.bulk_create(agencies) except Exception as e: logger.error(f"Error creating federal agencies: {e}") + + @classmethod + def get_non_federal_agency(cls): + """Returns the non-federal agency.""" + return FederalAgency.objects.filter(agency="Non-Federal Agency").first() \ No newline at end of file diff --git a/src/registrar/models/portfolio.py b/src/registrar/models/portfolio.py index b3131cb87..3382de98a 100644 --- a/src/registrar/models/portfolio.py +++ b/src/registrar/models/portfolio.py @@ -6,9 +6,9 @@ from registrar.models.federal_agency import FederalAgency from .utility.time_stamped_model import TimeStampedModel -def get_default_federal_agency(): - """returns non-federal agency""" - return FederalAgency.objects.filter(agency="Non-Federal Agency").first() +# def get_default_federal_agency(): +# """returns non-federal agency""" +# return FederalAgency.objects.filter(agency="Non-Federal Agency").first() class Portfolio(TimeStampedModel): @@ -20,7 +20,7 @@ class Portfolio(TimeStampedModel): # use the short names in Django admin OrganizationChoices = DomainRequest.OrganizationChoices StateTerritoryChoices = DomainRequest.StateTerritoryChoices - + # Stores who created this model. If no creator is specified in DJA, # then the creator will default to the current request user""" creator = models.ForeignKey("registrar.User", on_delete=models.PROTECT, help_text="Associated user", unique=False) @@ -35,7 +35,7 @@ class Portfolio(TimeStampedModel): on_delete=models.PROTECT, help_text="Associated federal agency", unique=False, - default=get_default_federal_agency, + default=FederalAgency.get_non_federal_agency, ) organization_type = models.CharField(