Browse Source

Merge pull request #23 from sbrandtb/fix_mac_len

Check for string length on EUI causes error
jimfunk 10 years ago
parent
commit
0a3bdf2dcb
2 changed files with 5 additions and 4 deletions
  1. 0 4
      netfields/fields.py
  2. 5 0
      netfields/forms.py

+ 0 - 4
netfields/fields.py

@@ -92,10 +92,6 @@ class CidrAddressField(_NetAddressField):
 class MACAddressField(models.Field):
     description = "PostgreSQL MACADDR field"
 
-    def __init__(self, *args, **kwargs):
-        kwargs['max_length'] = 17
-        super(MACAddressField, self).__init__(*args, **kwargs)
-
     def db_type(self, connection):
         return 'macaddr'
 

+ 5 - 0
netfields/forms.py

@@ -84,3 +84,8 @@ class MACAddressFormField(forms.Field):
             return EUI(value, dialect=mac_unix_common)
         except (AddrFormatError, TypeError):
             raise ValidationError(self.error_messages['invalid'])
+
+    def widget_attrs(self, widget):
+        attrs = super(MACAddressFormField, self).widget_attrs(widget)
+        attrs.update({'maxlength': '17'})
+        return attrs