django-ipyfield

IPy.IP instances with BigInt storage for Django models
Download

django-ipyfield Ranking & Summary

Advertisement

  • Rating:
  • License:
  • MIT/X Consortium Lic...
  • Publisher Name:
  • Owen Nelson
  • Publisher web site:
  • https://bitbucket.org/onelson/

django-ipyfield Tags


django-ipyfield Description

IPy.IP instances with BigInt storage for Django models django-ipyfield is a Django app that provides a model field for Django that allows the storage of an ip address as a BigInt on the db side by using IPy to handle conversion to an IPy.IP instance (or None) on the python side.Wut?In its way, it gives us a way to store both ipv4 and ipv6 consistently without having to throw them in long charfields. Also, it gives us an easy way to validate data as it comes in, while giving us access to additional meta information (basically everything that makes IPy so awesome).InstallationAdd this to your django project by installing with pip:pip install django-ipyfieldor with easy_install:easy_install django-ipyfieldUsageIn your models, do something like the following:from django.db import modelsfrom ipyfield.models import IPyFieldclass MyModel(models.Model): # the regular params should work well enough here ipaddr = IPyField() # ... and so onFrom here, any assignments to obj.ipaddr can be considered a constructor argument to a new IPy.IP instance. Anything IP() can use to make a new object can be used.When making queries, I added one extra piece of syntactical sugar. For __in (range) lookups, you can pass a CIDR notation address range, for example:MyModel.objects.filter(ipaddr__in='10.0.0.0/24')Currently you need to use this form of notation supported for this kind of query. For now, if you need to use a prefix-netmask style notation, pass it to IPy.IP yourself and use the resulting instance as your filter parameter. Requirements: · Python · Django


django-ipyfield Related Software