Skip to content

Commit

Permalink
Merge pull request #4564 from netbox-community/3147-csv-import-fields
Browse files Browse the repository at this point in the history
Closes #3147: Allow dynamic access to related objects during CSV import
  • Loading branch information
jeremystretch authored May 6, 2020
2 parents 0239be9 + 270d61c commit 9312dea
Show file tree
Hide file tree
Showing 17 changed files with 706 additions and 879 deletions.
35 changes: 10 additions & 25 deletions netbox/circuits/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
from tenancy.forms import TenancyFilterForm, TenancyForm
from tenancy.models import Tenant
from utilities.forms import (
APISelect, APISelectMultiple, add_blank_choice, BootstrapMixin, CommentField, CSVChoiceField, DatePicker,
DynamicModelChoiceField, DynamicModelMultipleChoiceField, SmallTextarea, SlugField, StaticSelect2,
StaticSelect2Multiple, TagFilterField,
APISelectMultiple, add_blank_choice, BootstrapMixin, CommentField, CSVChoiceField, CSVModelChoiceField,
CSVModelForm, DatePicker, DynamicModelChoiceField, DynamicModelMultipleChoiceField, SmallTextarea, SlugField,
StaticSelect2, StaticSelect2Multiple, TagFilterField,
)
from .choices import CircuitStatusChoices
from .models import Circuit, CircuitTermination, CircuitType, Provider
Expand Down Expand Up @@ -55,12 +55,6 @@ class ProviderCSVForm(CustomFieldModelCSVForm):
class Meta:
model = Provider
fields = Provider.csv_headers
help_texts = {
'name': 'Provider name',
'asn': '32-bit autonomous system number',
'portal_url': 'Portal URL',
'comments': 'Free-form comments',
}


class ProviderBulkEditForm(BootstrapMixin, AddRemoveTagsForm, CustomFieldBulkEditForm):
Expand Down Expand Up @@ -148,7 +142,7 @@ class Meta:
]


class CircuitTypeCSVForm(forms.ModelForm):
class CircuitTypeCSVForm(CSVModelForm):
slug = SlugField()

class Meta:
Expand Down Expand Up @@ -192,35 +186,26 @@ class Meta:


class CircuitCSVForm(CustomFieldModelCSVForm):
provider = forms.ModelChoiceField(
provider = CSVModelChoiceField(
queryset=Provider.objects.all(),
to_field_name='name',
help_text='Name of parent provider',
error_messages={
'invalid_choice': 'Provider not found.'
}
help_text='Assigned provider'
)
type = forms.ModelChoiceField(
type = CSVModelChoiceField(
queryset=CircuitType.objects.all(),
to_field_name='name',
help_text='Type of circuit',
error_messages={
'invalid_choice': 'Invalid circuit type.'
}
help_text='Type of circuit'
)
status = CSVChoiceField(
choices=CircuitStatusChoices,
required=False,
help_text='Operational status'
)
tenant = forms.ModelChoiceField(
tenant = CSVModelChoiceField(
queryset=Tenant.objects.all(),
required=False,
to_field_name='name',
help_text='Name of assigned tenant',
error_messages={
'invalid_choice': 'Tenant not found.'
}
help_text='Assigned tenant'
)

class Meta:
Expand Down
5 changes: 3 additions & 2 deletions netbox/circuits/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ class Provider(ChangeLoggedModel, CustomFieldModel):
asn = ASNField(
blank=True,
null=True,
verbose_name='ASN'
verbose_name='ASN',
help_text='32-bit autonomous system number'
)
account = models.CharField(
max_length=30,
Expand All @@ -47,7 +48,7 @@ class Provider(ChangeLoggedModel, CustomFieldModel):
)
portal_url = models.URLField(
blank=True,
verbose_name='Portal'
verbose_name='Portal URL'
)
noc_contact = models.TextField(
blank=True,
Expand Down
Loading

0 comments on commit 9312dea

Please sign in to comment.