fix block edit

issues:
1. IPAddressField is deprecated. We can change this without consequence
because the underlying field type is not changed.
2. New admin was not wired up.
3. There was a admin bug when one end of the block is zero.
pull/1/head
eric 2016-11-09 15:24:11 -05:00
parent a49be9e61f
commit b252d0b7df
2 changed files with 10 additions and 5 deletions

View File

@ -5,7 +5,7 @@ from selectable.base import ModelLookup
from selectable.registry import registry from selectable.registry import registry
from django import forms from django import forms
from django.contrib.admin import ModelAdmin from django.contrib.admin import ModelAdmin, site
from django.contrib.auth.models import User, Group from django.contrib.auth.models import User, Group
class UserLookup(ModelLookup): class UserLookup(ModelLookup):
@ -47,3 +47,8 @@ class CardPatternAdmin(ModelAdmin):
class EmailPatternAdmin(ModelAdmin): class EmailPatternAdmin(ModelAdmin):
list_display = ('library', 'pattern', ) list_display = ('library', 'pattern', )
search_fields = ('library__name',) search_fields = ('library__name',)
site.register(models.Library, LibraryAdmin)
site.register(models.Block, BlockAdmin)
site.register(models.CardPattern, CardPatternAdmin)
site.register(models.EmailPattern, EmailPatternAdmin)

View File

@ -140,7 +140,7 @@ class IP(object):
if not isinstance(other, IP): if not isinstance(other, IP):
other = IP(other) other = IP(other)
if self.int and other.int: if self.int is not None and other.int is not None:
return self.int.__cmp__(other.int) return self.int.__cmp__(other.int)
raise ValueError('Invalid arguments') raise ValueError('Invalid arguments')
@ -177,7 +177,7 @@ class IPAddressFormField(BaseIPAddressField):
raise ValidationError(self.default_error_messages['invalid'], raise ValidationError(self.default_error_messages['invalid'],
code='invalid') code='invalid')
class IPAddressModelField(models.IPAddressField): class IPAddressModelField(models.GenericIPAddressField):
__metaclass__ = models.SubfieldBase __metaclass__ = models.SubfieldBase
empty_strings_allowed = False empty_strings_allowed = False
@ -205,10 +205,10 @@ class IPAddressModelField(models.IPAddressField):
def formfield(self, **kwargs): def formfield(self, **kwargs):
defaults = {'form_class': IPAddressFormField} defaults = {'form_class': IPAddressFormField}
defaults.update(kwargs) defaults.update(kwargs)
return super(models.IPAddressField, self).formfield(**defaults) return super(models.GenericIPAddressField, self).formfield(**defaults)
def deconstruct(self): def deconstruct(self):
name, path, args, kwargs = super(models.IPAddressField, self).deconstruct() name, path, args, kwargs = super(models.GenericIPAddressField, self).deconstruct()
return name, path, args, kwargs return name, path, args, kwargs
class Block(models.Model): class Block(models.Model):