Created
April 30, 2013 14:16
-
-
Save csarcom/5489022 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class IPField(models.Field): | |
__metaclass__ = models.SubfieldBase | |
description = 'IP Field' | |
def get_db_prep_value(self, value, connection, prepared=False): | |
value = super(IPField, self | |
).get_db_prep_value(value, connection, prepared) | |
if value is not None: | |
tmp = ipaddr.IPAddress(value) | |
if ':' in value: | |
return tmp.packed | |
else: | |
return 12*'\0' + tmp.packed | |
return value | |
# def get_prep_value(self, value): | |
# if not value: | |
# return 'NULL' | |
# else: | |
# tmp = ipaddr.IPAddress(value) | |
# if ':' in value: | |
# return tmp.packed | |
# else: | |
# return 12*'\0' + tmp.packed |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment