Add has_coordinates filter to Site #45

Closed
opened 2026-04-05 16:21:19 +02:00 by MrUnknownDE · 0 comments
Owner

Originally created by @jirivrany on 3/31/2026

NetBox version

v4.5.5

Feature type

Change to existing functionality

Proposed functionality

Add a has_coordinates boolean filter to SiteFilterSet and SiteFilterForm that allows filtering Sites by whether both GPS coordinates (latitude and longitude) are set.

The Site model already has latitude and longitude fields (both nullable DecimalField). The proposed changes are minimal — no migrations, no new imports:

dcim/filtersets.py — add to SiteFilterSet:

has_coordinates = django_filters.BooleanFilter(
    method='_has_coordinates',
    label=_('Has coordinates'),
)

def _has_coordinates(self, queryset, name, value):
    params = Q(latitude__isnull=False) & Q(longitude__isnull=False)
    if value:
        return queryset.filter(params)
    return queryset.exclude(params)

dcim/forms/filtersets.py — add has_coordinates NullBooleanField to SiteFilterForm and include it in the Attributes fieldset.

The implementation mirrors the existing has_primary_ip filter on DeviceFilterSet.

Use case

When managing a large number of Sites, operators need to quickly identify which Sites are missing GPS coordinates — for example, before placing them on a map or running a geo-based report. Currently there is no way to filter for this in the Site list without exporting and post-processing the data.

Database changes

None

External dependencies

None

*Originally created by @jirivrany on 3/31/2026* ### NetBox version v4.5.5 ### Feature type Change to existing functionality ### Proposed functionality Add a `has_coordinates` boolean filter to `SiteFilterSet` and `SiteFilterForm` that allows filtering Sites by whether both GPS coordinates (`latitude` and `longitude`) are set. The `Site` model already has `latitude` and `longitude` fields (both nullable `DecimalField`). The proposed changes are minimal — no migrations, no new imports: **`dcim/filtersets.py`** — add to `SiteFilterSet`: ```python has_coordinates = django_filters.BooleanFilter( method='_has_coordinates', label=_('Has coordinates'), ) def _has_coordinates(self, queryset, name, value): params = Q(latitude__isnull=False) & Q(longitude__isnull=False) if value: return queryset.filter(params) return queryset.exclude(params) ``` **`dcim/forms/filtersets.py`** — add `has_coordinates` NullBooleanField to `SiteFilterForm` and include it in the `Attributes` fieldset. The implementation mirrors the existing `has_primary_ip` filter on `DeviceFilterSet`. ### Use case When managing a large number of Sites, operators need to quickly identify which Sites are missing GPS coordinates — for example, before placing them on a map or running a geo-based report. Currently there is no way to filter for this in the Site list without exporting and post-processing the data. ### Database changes None ### External dependencies None
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github/netbox#45