Skip to content

Conversation

@TomGrozev
Copy link
Contributor

Fixes: #5344

This adds support for having custom fields in list view tables. All changes are make in the BaseTable class to prevent changing on every table object. Since the custom fields are JSON, if the value is a list they will be displayed as labels.

The mentioned issue is marked blocked but this should be removed since the release of 2.10.

@ypid
Copy link
Contributor

ypid commented Dec 18, 2020

Works nicely 👍 I applied this patch on v2.10.1 and just tested a bit. I will continue using this patch and see if anything breaks.

Edit: It is only a front end change, no database migration or something. So I feel safe running this patch and will take responsibility if something breaks.

@jeremystretch jeremystretch changed the base branch from develop to feature December 22, 2020 20:48
@ecoutinho
Copy link

On v2.10.2 is also working has expected. Thanks for this feature.

@DanSheps
Copy link
Member

@ypid @ecoutinho Keep in mind we will not support you deploying this to your current instances and you will be responsible for resolving any issues you encounter yourself.

@tom0010
Copy link

tom0010 commented Jan 21, 2021

I just tested on the docker instance (v2.10.3) - working fine for me right now, so thanks.
When can we expect this to be merged?
How is this different to #5576?

@ecraven
Copy link

ecraven commented Feb 3, 2021

just tried this on 2.10.3 (by just replacing the entire table.py file), and it works fine in IP Addresses view. But when looking at one Prefix, and at its ip addresses, I see the following:
maim
Each reload changes the number of times the fields are repeated, sometimes only once, sometimes many times.
This is a great patch, would be very helpful to get it merged!

@trytrytogo
Copy link

trytrytogo commented Feb 21, 2021

just tried this on 2.10.3 (by just replacing the entire table.py file), and it works fine in IP Addresses view. But when looking at one Prefix, and at its ip addresses, I see the following:
maim
Each reload changes the number of times the fields are repeated, sometimes only once, sometimes many times.
This is a great patch, would be very helpful to get it merged!

Replaced the entire tables.py
same problems too in "dcim/devices/"

netbox (v2.10.3)

@xkilian
Copy link

xkilian commented Mar 2, 2021

@TomGrozev Can you adress the issues raised by @ecraven and @ixinshang? I think we are not too far off.

@keitarobr
Copy link

@TomGrozev Can you adress the issues raised by @ecraven and @ixinshang? I think we are not too far off.

A quick fix:

(venv) rodrigo@ufsclinux:~/CGR/netbox/netbox$ git diff
diff --git a/netbox/utilities/tables.py b/netbox/utilities/tables.py
index 4a796435..cd5af482 100644
--- a/netbox/utilities/tables.py
+++ b/netbox/utilities/tables.py
@@ -33,7 +33,7 @@ class BaseTable(tables.Table):
             label = cf.label if cf.label != '' else cf.name
             self.base_columns[name] = CustomFieldColumn(verbose_name=label)
             custom_fields[name] = cf
-        self._meta.fields += tuple(custom_fields.keys())
+        self._meta.fields += tuple(x for x in custom_fields.keys() if x not in self._meta.fields)
 
         # Init table
         super().__init__(*args, **kwargs)

@trytrytogo
Copy link

@TomGrozev Can you adress the issues raised by @ecraven and @ixinshang? I think we are not too far off.

A quick fix:

(venv) rodrigo@ufsclinux:~/CGR/netbox/netbox$ git diff
diff --git a/netbox/utilities/tables.py b/netbox/utilities/tables.py
index 4a796435..cd5af482 100644
--- a/netbox/utilities/tables.py
+++ b/netbox/utilities/tables.py
@@ -33,7 +33,7 @@ class BaseTable(tables.Table):
             label = cf.label if cf.label != '' else cf.name
             self.base_columns[name] = CustomFieldColumn(verbose_name=label)
             custom_fields[name] = cf
-        self._meta.fields += tuple(custom_fields.keys())
+        self._meta.fields += tuple(x for x in custom_fields.keys() if x not in self._meta.fields)
 
         # Init table
         super().__init__(*args, **kwargs)

@keitarobr hi,i changed code in tables.py in 36 line.
i have a test in device. it's ok.
Finally, I hope this feature appears in the official stable version.

thanks all.

@jeremystretch jeremystretch changed the base branch from feature to 5344-table-custom-fields March 29, 2021 21:14
@jeremystretch
Copy link
Member

Thanks @TomGrozev. Merging this into a local branch to wrap it up for v2.11.

@jeremystretch jeremystretch merged commit be3d33e into netbox-community:5344-table-custom-fields Mar 29, 2021
jathanism pushed a commit to nautobot/nautobot that referenced this pull request Jul 20, 2021
This change adds custom fields to tables based on the work of [TomGrozev](https://github.com/TomGrozev) and [keitarobr](https://github.com/keitarobr) in netbox-community/netbox#5460 (already merged).

Co-authored-by: Glenn Matthews <[email protected]>
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 25, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support custom fields in user table configuration

10 participants