mirror of
https://github.com/netbox-community/netbox.git
synced 2025-07-22 20:12:00 -06:00
PowerFeed.supply to slug (#3569)
This commit is contained in:
parent
62494f295e
commit
bb8b012397
@ -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,
|
||||
|
@ -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,
|
||||
}
|
||||
|
@ -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 = (
|
||||
|
@ -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()
|
||||
)
|
||||
|
@ -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
|
||||
),
|
||||
|
||||
]
|
||||
|
@ -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,
|
||||
|
Loading…
Reference in New Issue
Block a user