Separate field for postal code #7964

Closed
opened 2025-12-29 20:30:33 +01:00 by adam · 5 comments
Owner

Originally created by @candlerb on GitHub (Apr 29, 2023).

NetBox version

v3.4.10

Feature type

Data model extension

Proposed functionality

Although in general I approve of simple, unstructured data for physical address and shipping address, it would be very helpful to have a separate field for "Postal code".

Use case

I need to be able to view, sort and filter on postal codes, and for cross-referencing to other data sources.

Right now I have created a custom field on Site for postal code, and this works fine. There's only one problem: I have removed the postal code from physical address to avoid data duplication, but now the "Map" link button doesn't have that information available to it, making the map lookups less accurate.

Ideally, the Map button would combine physical address and postal code for sending to Google Maps. To do that, it needs the postal code in an official model field (or for the physical address map button to be a user-defined template).

Database changes

Separate field in Site for postal code.


Aside: I observe that different countries have different postal code schemes, so in principle you'd need the tuple of (country, postal code) to identify a geographical area. However, the country information is likely to exist already in the Region hierarchy; and for the benefit of Google Maps, you can still include the country within the physical address field.

External dependencies

None

Originally created by @candlerb on GitHub (Apr 29, 2023). ### NetBox version v3.4.10 ### Feature type Data model extension ### Proposed functionality Although in general I approve of simple, unstructured data for physical address and shipping address, it would be very helpful to have a separate field for "Postal code". ### Use case I need to be able to view, sort and filter on postal codes, and for cross-referencing to other data sources. Right now I have created a custom field on Site for postal code, and this works fine. There's only one problem: I have removed the postal code from physical address to avoid data duplication, but now the "Map" link button doesn't have that information available to it, making the map lookups less accurate. Ideally, the Map button would combine physical address and postal code for sending to Google Maps. To do that, it needs the postal code in an official model field (or for the physical address map button to be a user-defined template). ### Database changes Separate field in Site for postal code. ---- Aside: I observe that different countries have different postal code schemes, so in principle you'd need the tuple of (country, postal code) to identify a geographical area. However, the country information is likely to exist already in the Region hierarchy; and for the benefit of Google Maps, you can still include the country within the physical address field. ### External dependencies None
adam added the type: featurepending closurestatus: under review labels 2025-12-29 20:30:33 +01:00
adam closed this issue 2025-12-29 20:30:33 +01:00
Author
Owner

@candlerb commented on GitHub (May 5, 2023):

Workaround: add a custom link

# Link text
{% if object.physical_address or object.cf.postcode %}
Map
{% endif %}

# Link URL
https://maps.google.com?q={{ object.physical_address }} {{object.cf.postcode}}

However, I don't see a way to disable the existing "Map" button which sits over the physical_address field.

That could be done with a small patch to templates/dcim/site.html:

              {% if object.physical_address %}

becomes

              {% if object.physical_address and config.MAPS_URL %}
@candlerb commented on GitHub (May 5, 2023): Workaround: add a custom link ``` # Link text {% if object.physical_address or object.cf.postcode %} Map {% endif %} # Link URL https://maps.google.com?q={{ object.physical_address }} {{object.cf.postcode}} ``` However, I don't see a way to disable the existing "Map" button which sits over the physical_address field. That could be done with a small patch to templates/dcim/site.html: ``` {% if object.physical_address %} ``` becomes ``` {% if object.physical_address and config.MAPS_URL %} ```
Author
Owner

@jeremystretch commented on GitHub (May 5, 2023):

This was discussed under #9617, however no progress was made due to the lack of a well-defined international standard detailing what the supported address fields should be. IMO it doesn't make sense to add a discrete field just for postal code, which we wouldn't even be able to validate.

@jeremystretch commented on GitHub (May 5, 2023): This was discussed under #9617, however no progress was made due to the lack of a well-defined international standard detailing what the supported address fields should be. IMO it doesn't make sense to add a discrete field just for postal code, which we wouldn't even be able to validate.
Author
Owner

@candlerb commented on GitHub (May 5, 2023):

I agree that it would be a bad idea to split the address fully into separate lines for "street", "city", "state/province" etc partly for the reasons you describe, and partly because it would make importing addresses into Netbox very hard.

I do think the concept of "postal code" is well-defined and straightforward though. Countries either have them, or they don't.

I'm not concerned that it wouldn't be validated: firstly because addresses in Netbox are not validated anyway; and secondly because the user could configure their own custom validation suitable for their environment.

For me it's important to be able to sort and filter on postal code, and a custom field achieves that (as indeed it would if someone wants more structured addresses). Another option then is to make the button which links to Google Maps have a templated URL, and/or to be able to disable it entirely (#12498) so that a custom link can be used for the map link.

Aside: in LDAP, RFC4519 defines "postalAddress" and "postalCode" attributes. There are also more specific attributes available like "street", but that "contains site information from a postal address". The example in 2.23 suggests that postalAddress doesn't include the postalCode, but it's not clearly defined.

@candlerb commented on GitHub (May 5, 2023): I agree that it would be a bad idea to split the address fully into separate lines for "street", "city", "state/province" etc partly for the reasons you describe, and partly because it would make importing addresses into Netbox very hard. I do think the concept of "postal code" is well-defined and straightforward though. Countries either have them, or they don't. I'm not concerned that it wouldn't be validated: firstly because addresses in Netbox are not validated anyway; and secondly because the user could configure their own custom validation suitable for their environment. For me it's important to be able to sort and filter on postal code, and a custom field achieves that (as indeed it would if someone wants more structured addresses). Another option then is to make the button which links to Google Maps have a templated URL, and/or to be able to disable it entirely (#12498) so that a custom link can be used for the map link. Aside: in LDAP, [RFC4519](https://datatracker.ietf.org/doc/rfc4519/) defines "postalAddress" and "postalCode" attributes. There are also more specific attributes available like "street", but that _"contains site information from a postal address"_. The example in 2.23 suggests that postalAddress doesn't include the postalCode, but it's not clearly defined.
Author
Owner

@github-actions[bot] commented on GitHub (Aug 8, 2023):

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. NetBox is governed by a small group of core maintainers which means not all opened issues may receive direct feedback. Do not attempt to circumvent this process by "bumping" the issue; doing so will result in its immediate closure and you may be barred from participating in any future discussions. Please see our contributing guide.

@github-actions[bot] commented on GitHub (Aug 8, 2023): This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. NetBox is governed by a small group of core maintainers which means not all opened issues may receive direct feedback. **Do not** attempt to circumvent this process by "bumping" the issue; doing so will result in its immediate closure and you may be barred from participating in any future discussions. Please see our [contributing guide](https://github.com/netbox-community/netbox/blob/develop/CONTRIBUTING.md).
Author
Owner

@github-actions[bot] commented on GitHub (Sep 7, 2023):

This issue has been automatically closed due to lack of activity. In an effort to reduce noise, please do not comment any further. Note that the core maintainers may elect to reopen this issue at a later date if deemed necessary.

@github-actions[bot] commented on GitHub (Sep 7, 2023): This issue has been automatically closed due to lack of activity. In an effort to reduce noise, please do not comment any further. Note that the core maintainers may elect to reopen this issue at a later date if deemed necessary.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#7964