From 4d3fb52274252a7e7f8a788552f3b6b717dfa95e Mon Sep 17 00:00:00 2001 From: "John C. Allwein" Date: Mon, 3 Aug 2020 20:43:39 -0400 Subject: [PATCH] fields: support subnet masks via ip_address --- mirrors/fields.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/mirrors/fields.py b/mirrors/fields.py index 985c11ec..3216d831 100644 --- a/mirrors/fields.py +++ b/mirrors/fields.py @@ -3,7 +3,12 @@ from django.core.exceptions import ValidationError from django.db import models -from ipaddress import ip_address as IP +from ipaddress import ip_address, ip_interface + +def IP(address): + if '/' not in address: + return ip_address(address) + return ip_interface(address) class IPNetworkFormField(forms.Field): def to_python(self, value):