diff --git a/netbox/dcim/api/serializers.py b/netbox/dcim/api/serializers.py index 7883ca169..1f7603241 100644 --- a/netbox/dcim/api/serializers.py +++ b/netbox/dcim/api/serializers.py @@ -699,8 +699,8 @@ class PowerFeedSerializer(TaggitSerializer, CustomFieldModelSerializer): default=POWERFEED_STATUS_ACTIVE ) supply = ChoiceField( - choices=POWERFEED_SUPPLY_CHOICES, - default=POWERFEED_SUPPLY_AC + choices=PowerFeedSupplyChoices, + default=PowerFeedSupplyChoices.SUPPLY_AC ) phase = ChoiceField( choices=POWERFEED_PHASE_CHOICES, diff --git a/netbox/dcim/choices.py b/netbox/dcim/choices.py index 7b7b18b4d..5d44f1cf4 100644 --- a/netbox/dcim/choices.py +++ b/netbox/dcim/choices.py @@ -892,3 +892,19 @@ class PowerFeedTypeChoices(ChoiceSet): TYPE_PRIMARY: 1, TYPE_REDUNDANT: 2, } + + +class PowerFeedSupplyChoices(ChoiceSet): + + SUPPLY_AC = 'ac' + SUPPLY_DC = 'dc' + + CHOICES = ( + (SUPPLY_AC, 'Primary'), + (SUPPLY_DC, 'Redundant'), + ) + + LEGACY_MAP = { + SUPPLY_AC: 1, + SUPPLY_DC: 2, + } diff --git a/netbox/dcim/constants.py b/netbox/dcim/constants.py index 8a574b185..13335de3f 100644 --- a/netbox/dcim/constants.py +++ b/netbox/dcim/constants.py @@ -68,12 +68,6 @@ COMPATIBLE_TERMINATION_TYPES = { } # Power feeds -POWERFEED_SUPPLY_AC = 1 -POWERFEED_SUPPLY_DC = 2 -POWERFEED_SUPPLY_CHOICES = ( - (POWERFEED_SUPPLY_AC, 'AC'), - (POWERFEED_SUPPLY_DC, 'DC'), -) POWERFEED_PHASE_SINGLE = 1 POWERFEED_PHASE_3PHASE = 3 POWERFEED_PHASE_CHOICES = ( diff --git a/netbox/dcim/forms.py b/netbox/dcim/forms.py index 32d60ace7..f767d0903 100644 --- a/netbox/dcim/forms.py +++ b/netbox/dcim/forms.py @@ -3865,7 +3865,7 @@ class PowerFeedCSVForm(forms.ModelForm): help_text='Primary or redundant' ) supply = CSVChoiceField( - choices=POWERFEED_SUPPLY_CHOICES, + choices=PowerFeedSupplyChoices, required=False, help_text='AC/DC' ) @@ -3942,7 +3942,7 @@ class PowerFeedBulkEditForm(BootstrapMixin, AddRemoveTagsForm, CustomFieldBulkEd widget=StaticSelect2() ) supply = forms.ChoiceField( - choices=add_blank_choice(POWERFEED_SUPPLY_CHOICES), + choices=add_blank_choice(PowerFeedSupplyChoices), required=False, initial='', widget=StaticSelect2() @@ -4019,7 +4019,7 @@ class PowerFeedFilterForm(BootstrapMixin, CustomFieldFilterForm): widget=StaticSelect2() ) supply = forms.ChoiceField( - choices=add_blank_choice(POWERFEED_SUPPLY_CHOICES), + choices=add_blank_choice(PowerFeedSupplyChoices), required=False, widget=StaticSelect2() ) diff --git a/netbox/dcim/migrations/0084_3569_powerfeed_fields.py b/netbox/dcim/migrations/0084_3569_powerfeed_fields.py index d40d367e6..5004258bd 100644 --- a/netbox/dcim/migrations/0084_3569_powerfeed_fields.py +++ b/netbox/dcim/migrations/0084_3569_powerfeed_fields.py @@ -6,6 +6,11 @@ POWERFEED_TYPE_CHOICES = ( (2, 'redundant'), ) +POWERFEED_SUPPLY_CHOICES = ( + (1, 'ac'), + (2, 'dc'), +) + def powerfeed_type_to_slug(apps, schema_editor): PowerFeed = apps.get_model('dcim', 'PowerFeed') @@ -13,6 +18,12 @@ def powerfeed_type_to_slug(apps, schema_editor): PowerFeed.objects.filter(type=id).update(type=slug) +def powerfeed_supply_to_slug(apps, schema_editor): + PowerFeed = apps.get_model('dcim', 'PowerFeed') + for id, slug in POWERFEED_SUPPLY_CHOICES: + PowerFeed.objects.filter(supply=id).update(supply=slug) + + class Migration(migrations.Migration): atomic = False @@ -22,7 +33,7 @@ class Migration(migrations.Migration): operations = [ - # Cable.type + # PowerFeed.type migrations.AlterField( model_name='powerfeed', name='type', @@ -32,4 +43,14 @@ class Migration(migrations.Migration): code=powerfeed_type_to_slug ), + # PowerFeed.supply + migrations.AlterField( + model_name='powerfeed', + name='supply', + field=models.CharField(blank=True, max_length=50), + ), + migrations.RunPython( + code=powerfeed_supply_to_slug + ), + ] diff --git a/netbox/dcim/models.py b/netbox/dcim/models.py index c1b951496..3b9ee069e 100644 --- a/netbox/dcim/models.py +++ b/netbox/dcim/models.py @@ -3112,12 +3112,14 @@ class PowerFeed(ChangeLoggedModel, CableTermination, CustomFieldModel): default=POWERFEED_STATUS_ACTIVE ) type = models.CharField( + max_length=50, choices=PowerFeedTypeChoices, default=PowerFeedTypeChoices.TYPE_PRIMARY ) - supply = models.PositiveSmallIntegerField( - choices=POWERFEED_SUPPLY_CHOICES, - default=POWERFEED_SUPPLY_AC + supply = models.CharField( + max_length=50, + choices=PowerFeedSupplyChoices, + default=PowerFeedSupplyChoices.SUPPLY_AC ) phase = models.PositiveSmallIntegerField( choices=POWERFEED_PHASE_CHOICES,