def does_ip_exist(ip_addr, netbox_id=None):
"""Checks if the given IP already exist in database.
Parameters:
* ip_addr - the IP addres to look for.
* netbox_id - a netbox primary key that can have the given ip_addr, and
the function will still return False.
Returns:
- True if the IP already exists in the database (and the netbox with the
IP is not the same as the given netbox_id).
- False if not.
"""
if netbox_id:
ip_qs = Netbox.objects.filter(Q(ip=unicode(ip_addr)), ~Q(id=netbox_id))
else:
ip_qs = Netbox.objects.filter(ip=unicode(ip_addr))
return ip_qs.count() > 0
评论列表
文章目录