fix IP display in LibraryAuth

pull/94/head
eric 2021-09-09 16:01:32 -04:00
parent 9d1bb7f8bf
commit 7dc1760fb1
2 changed files with 10 additions and 4 deletions

View File

@ -38,7 +38,7 @@ class LibraryAdmin(ModelAdmin):
@register(models.Block)
class BlockAdmin(ModelAdmin):
list_display = ('library', 'lower', 'upper',)
list_display = ('library', 'lower_IP', 'upper_IP',)
search_fields = ('library__name', 'lower', 'upper',)
@register(models.CardPattern)

View File

@ -233,7 +233,7 @@ class Block(models.Model):
upper = IPAddressModelField(db_index=True, blank=True, null=True)
def clean(self):
if self.upper and self.upper.int:
if self.upper:
try:
if self.lower > self.upper:
raise ValidationError('Lower end of the Block must be less '
@ -243,10 +243,16 @@ class Block(models.Model):
def __str__(self):
if self.upper and self.upper.int:
return u'%s %s-%s' % (self.library, self.lower, self.upper)
if self.upper:
return u'%s %s - %s' % (self.library, IP(self.lower), IP(self.upper))
return u'%s %s' % (self.library, self.lower)
def upper_IP(self):
return IP(self.upper)
def lower_IP(self):
return IP(self.lower)
class Meta:
ordering = ['lower',]