Skip to content

Commit

Permalink
Replaced AddressFormField by IPAM IPAddressFormField
Browse files Browse the repository at this point in the history
  • Loading branch information
peteeckel committed Oct 13, 2024
1 parent ccf7101 commit af9d23b
Showing 1 changed file with 3 additions and 21 deletions.
24 changes: 3 additions & 21 deletions netbox_dns/fields/address.py
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,31 +1,13 @@
from django import forms
from django.db import models
from django.core.exceptions import ValidationError
from django.utils.translation import gettext_lazy as _

from netaddr import AddrFormatError, IPAddress

from ipam.formfields import IPAddressFormField

__all__ = (
"AddressFormField",
"AddressField",
)


class AddressFormField(forms.Field):
def to_python(self, value):
if not value:
return None

if isinstance(value, IPAddress):
return value

try:
ip_address = IPAddress(value)
except AddrFormatError as exc:
raise ValidationError(exc)

return ip_address
__all__ = ("AddressField",)


class AddressField(models.Field):
Expand Down Expand Up @@ -58,7 +40,7 @@ def get_prep_value(self, value):
return str(self.to_python(value))

def form_class(self):
return AddressFormField
return IPAddressFormField

def formfield(self, **kwargs):
defaults = {"form_class": self.form_class()}
Expand Down

0 comments on commit af9d23b

Please sign in to comment.