Rack group filter on devices #200

Closed
opened 2025-12-29 16:19:16 +01:00 by adam · 1 comment
Owner

Originally created by @bellwood on GitHub (Jul 12, 2016).

This would be extremely helpful.

Originally created by @bellwood on GitHub (Jul 12, 2016). This would be extremely helpful.
adam added the type: feature label 2025-12-29 16:19:16 +01:00
adam closed this issue 2025-12-29 16:19:17 +01:00
Author
Owner

@bellwood commented on GitHub (Jul 13, 2016):

Just some notes:

Per our irc conversation:

presumably I also have to update /dcim/filters.py "class DeviceFilter" too correct to enable the actual filtering? 

i tried added the two "django_filters.ModelMultipleChoiceFilter" for group and group_id but it errors and debug tells me i have a field error, the rack group bits arent available fields

none of the choices relate to rack group

Specific changes to /dcim/filters.py:

Add:

    group_id = django_filters.ModelMultipleChoiceFilter(
        name='group',
        queryset=RackGroup.objects.all(),
        label='Group (ID)',
    )
    group = django_filters.ModelMultipleChoiceFilter(
        name='group',
        queryset=RackGroup.objects.all(),
        to_field_name='slug',
        label='Group',
    )

To...
class DeviceFilter(django_filters.FilterSet):

...at line 190 and then edit class meta to include those:

    class Meta:
        model = Device
        fields = ['q', 'name', 'site_id', 'site', 'rack_id', 'role_id', 'role', 'device_type_id', 'manufacturer_id',
                  'manufacturer', 'model', 'platform_id', 'platform', 'status', 'is_console_server', 'is_pdu',
                  'is_network_device', 'group_id', 'group']

The debug error is:

FieldError at /dcim/devices/
Cannot resolve keyword 'group' into field. Choices are: comments, console_ports, created, cs_ports, device_bays, device_role, device_role_id, device_type, device_type_id, face, id, interfaces, last_updated, modules, name, parent_bay, platform, platform_id, position, power_outlets, power_ports, primary_ip4, primary_ip4_id, primary_ip6, primary_ip6_id, rack, rack_id, secrets, serial, status
@bellwood commented on GitHub (Jul 13, 2016): Just some notes: Per our irc conversation: ``` presumably I also have to update /dcim/filters.py "class DeviceFilter" too correct to enable the actual filtering? i tried added the two "django_filters.ModelMultipleChoiceFilter" for group and group_id but it errors and debug tells me i have a field error, the rack group bits arent available fields none of the choices relate to rack group ``` Specific changes to /dcim/filters.py: Add: ``` group_id = django_filters.ModelMultipleChoiceFilter( name='group', queryset=RackGroup.objects.all(), label='Group (ID)', ) group = django_filters.ModelMultipleChoiceFilter( name='group', queryset=RackGroup.objects.all(), to_field_name='slug', label='Group', ) ``` To... `class DeviceFilter(django_filters.FilterSet):` ...at line 190 and then edit `class meta` to include those: ``` class Meta: model = Device fields = ['q', 'name', 'site_id', 'site', 'rack_id', 'role_id', 'role', 'device_type_id', 'manufacturer_id', 'manufacturer', 'model', 'platform_id', 'platform', 'status', 'is_console_server', 'is_pdu', 'is_network_device', 'group_id', 'group'] ``` The debug error is: ``` FieldError at /dcim/devices/ Cannot resolve keyword 'group' into field. Choices are: comments, console_ports, created, cs_ports, device_bays, device_role, device_role_id, device_type, device_type_id, face, id, interfaces, last_updated, modules, name, parent_bay, platform, platform_id, position, power_outlets, power_ports, primary_ip4, primary_ip4_id, primary_ip6, primary_ip6_id, rack, rack_id, secrets, serial, status ```
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#200