Bulk import custom fields #443

Closed
opened 2025-12-29 16:22:14 +01:00 by adam · 7 comments
Owner

Originally created by @rgstori on GitHub (Sep 21, 2016).

Originally assigned to: @jeremystretch on GitHub.

I'd like the possibility, one some custom fields are defined, to have them importable in bulk.

Originally created by @rgstori on GitHub (Sep 21, 2016). Originally assigned to: @jeremystretch on GitHub. I'd like the possibility, one some custom fields are defined, to have them importable in bulk.
adam added the status: acceptedtype: feature labels 2025-12-29 16:22:14 +01:00
adam closed this issue 2025-12-29 16:22:14 +01:00
Author
Owner

@candlerb commented on GitHub (Jan 16, 2017):

Example use case:

I have added a custom field "FQDN" to the "ipam > IP Address" model. I'm importing a load of IP addresses in CSV format, and I want to import the corresponding FQDNs at the same time.

@candlerb commented on GitHub (Jan 16, 2017): Example use case: I have added a custom field "FQDN" to the "ipam > IP Address" model. I'm importing a load of IP addresses in CSV format, and I want to import the corresponding FQDNs at the same time.
Author
Owner

@paravoid commented on GitHub (Jul 18, 2017):

I had the same need for the DCIM/Device model. I very naively did:

--- a/netbox/dcim/forms.py
+++ b/netbox/dcim/forms.py
@@ -777,7 +777,7 @@ class DeviceForm(BootstrapMixin, TenancyForm, CustomFieldForm):
             self.initial['rack'] = self.instance.parent_bay.device.rack_id
 
 
-class BaseDeviceCSVForm(forms.ModelForm):
+class BaseDeviceCSVForm(BootstrapMixin, CustomFieldForm):
     device_role = forms.ModelChoiceField(
         queryset=DeviceRole.objects.all(),
         to_field_name='name',

…andi it seems to have done the trick: a new CSV field, prefixed with cf_ (in my case, cf_ticket) appeared on the form. I tried importing while populating that and it just worked :)

Are there complexities I haven't encountered yet or is it just that simple?

@paravoid commented on GitHub (Jul 18, 2017): I had the same need for the DCIM/Device model. I very naively did: ```diff --- a/netbox/dcim/forms.py +++ b/netbox/dcim/forms.py @@ -777,7 +777,7 @@ class DeviceForm(BootstrapMixin, TenancyForm, CustomFieldForm): self.initial['rack'] = self.instance.parent_bay.device.rack_id -class BaseDeviceCSVForm(forms.ModelForm): +class BaseDeviceCSVForm(BootstrapMixin, CustomFieldForm): device_role = forms.ModelChoiceField( queryset=DeviceRole.objects.all(), to_field_name='name', ``` …andi it seems to have done the trick: a new CSV field, prefixed with `cf_` (in my case, `cf_ticket`) appeared on the form. I tried importing while populating that and it just worked :) Are there complexities I haven't encountered yet or is it just that simple?
Author
Owner

@benclaussen commented on GitHub (Jan 24, 2018):

@paravoid I attempted this same thing in the IPAM forms.py (netbox/ipam/forms.py) the field appeared... however it also broke the API. When I attempted to load the API docs, I received an Internal Server Error and the error emails stated

Internal Server Error: /api/docs/

KeyError at /api/docs/
'en-us'

...

I don't know for certain if the API actually broke or if it was just Swagger docs...but something was unhappy.

Netbox v2.2.8
Python v2.7.12
Ubuntu server 16.04.3 LTS

@benclaussen commented on GitHub (Jan 24, 2018): @paravoid I attempted this same thing in the IPAM forms.py (`netbox/ipam/forms.py`) the field appeared... however it also broke the API. When I attempted to load the API docs, I received an `Internal Server Error` and the error emails stated ```` Internal Server Error: /api/docs/ KeyError at /api/docs/ 'en-us' ... ```` I don't know for certain if the API actually broke or if it was just Swagger docs...but something was unhappy. Netbox v2.2.8 Python v2.7.12 Ubuntu server 16.04.3 LTS
Author
Owner

@anthonyeden commented on GitHub (Mar 1, 2019):

I'm going to have a go at implementing this, and do a pull request. I'm thinking it would also make sense to export custom fields via the various CSV templates.

Does this sound good? Is it within scope of this ticket, or should I create a new one?

@anthonyeden commented on GitHub (Mar 1, 2019): I'm going to have a go at implementing this, and do a pull request. I'm thinking it would also make sense to *export* custom fields via the various CSV templates. Does this sound good? Is it within scope of this ticket, or should I create a new one?
Author
Owner

@anthonyeden commented on GitHub (Mar 1, 2019):

I've created a draft pull request to address Custom Field importing and exporting: #2949

Would a project maintainer be able to take a look and provide feedback?

@anthonyeden commented on GitHub (Mar 1, 2019): I've created a draft pull request to address Custom Field importing and exporting: #2949 Would a project maintainer be able to take a look and provide feedback?
Author
Owner

@iDemonix commented on GitHub (May 9, 2019):

After creating a very large CSV of data, mainly custom field data, we've also discovered this functionality isn't yet there.

Thanks for doing the work @anthonyeden, does your PR encompass imports for just Devices? Or does it cover Virtual Machines etc also?

@iDemonix commented on GitHub (May 9, 2019): After creating a very large CSV of data, mainly custom field data, we've also discovered this functionality isn't yet there. Thanks for doing the work @anthonyeden, does your PR encompass imports for just Devices? Or does it cover Virtual Machines etc also?
Author
Owner

@anthonyeden commented on GitHub (May 22, 2019):

Hi @iDemonix,

This pull request now encompasses all different CSV Import models. Would you mind testing it for me and reporting back here?

@anthonyeden commented on GitHub (May 22, 2019): Hi @iDemonix, This pull request now encompasses all different CSV Import models. Would you mind testing it for me and reporting back here?
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#443