forms not rendering data from api calls #1141

Closed
opened 2025-12-29 16:29:23 +01:00 by adam · 4 comments
Owner

Originally created by @jakeo on GitHub (Aug 3, 2017).

We recently upgraded netbox from a fairly old version to 2.1.1.

I'm not sure if this is a problem with our upgrade and the API, but when calling the API, there's no response.results list.

Here's what we did to work around the issue.

--- a/netbox/project-static/js/forms.js
+++ b/netbox/project-static/js/forms.js
@@ -105,7 +105,7 @@ $(document).ready(function() {
                     url: rendered_url,
                     dataType: 'json',
                     success: function(response, status) {
-                        $.each(response.results, function(index, choice) {
+                        $.each(response, function(index, choice) {
                             var option = $("<option></option>").attr("value", choice.id).text(choice[display_field]);
                             if (disabled_indicator && choice[disabled_indicator] && choice.id != initial_value) {
                                 option.attr("disabled", "disabled");

It looks like it was introduced here: https://github.com/digitalocean/netbox/commit/36bbcc85#diff-7d1368e3820dc752c181a5297633c221R107

Originally created by @jakeo on GitHub (Aug 3, 2017). We recently upgraded netbox from a fairly old version to 2.1.1. I'm not sure if this is a problem with our upgrade and the API, but when calling the API, there's no `response.results` list. Here's what we did to work around the issue. ``` --- a/netbox/project-static/js/forms.js +++ b/netbox/project-static/js/forms.js @@ -105,7 +105,7 @@ $(document).ready(function() { url: rendered_url, dataType: 'json', success: function(response, status) { - $.each(response.results, function(index, choice) { + $.each(response, function(index, choice) { var option = $("<option></option>").attr("value", choice.id).text(choice[display_field]); if (disabled_indicator && choice[disabled_indicator] && choice.id != initial_value) { option.attr("disabled", "disabled"); ``` It looks like it was introduced here: https://github.com/digitalocean/netbox/commit/36bbcc85#diff-7d1368e3820dc752c181a5297633c221R107
adam closed this issue 2025-12-29 16:29:23 +01:00
Author
Owner

@jeremystretch commented on GitHub (Aug 3, 2017):

I'm not sure if this is a problem with our upgrade and the API, but when calling the API, there's no response.results list.

This was added in v2.0. If you aren't seeing it, you're still running <2.0 code. Did you restart the WSGI service after upgrading?

@jeremystretch commented on GitHub (Aug 3, 2017): > I'm not sure if this is a problem with our upgrade and the API, but when calling the API, there's no response.results list. This was added in v2.0. If you aren't seeing it, you're still running <2.0 code. Did you restart the WSGI service after upgrading?
Author
Owner

@jakeo commented on GitHub (Aug 3, 2017):

@jeremystretch indeed we did upgrade.

Thanks for pointing me down the correct path. Looks like we were missing the REST_FRAMEWORK_* vars in our settinngs.py.

Thanks for netbox! Stellar work.

@jakeo commented on GitHub (Aug 3, 2017): @jeremystretch indeed we did upgrade. Thanks for pointing me down the correct path. Looks like we were missing the `REST_FRAMEWORK_*` vars in our `settinngs.py`. Thanks for netbox! Stellar work.
Author
Owner

@jeremystretch commented on GitHub (Aug 3, 2017):

FYI you should not edit settings.py. All configuration parameters are defined in configuration.py.

@jeremystretch commented on GitHub (Aug 3, 2017): FYI you should not edit `settings.py`. All configuration parameters are defined in `configuration.py`.
Author
Owner

@jakeo commented on GitHub (Aug 3, 2017):

We've added some other django modules our our netbox instance which require us modify settings.py.

@jakeo commented on GitHub (Aug 3, 2017): We've added some other django modules our our netbox instance which require us modify `settings.py`.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#1141