How it works

Data storage

All geoip data, including geograpy and geoip mapping is stored in the database.

Geography

Right now django-geoip supports only ipgeobase geography, which consist of following entities: Country, Region, City. Database maintains normalized relationships between all entities, i.e. Country has many Regions, Region has many Cities.

class django_geoip.models.Country(*args, **kwargs)

One country per row, contains country code and country name (TBD, #2)

class django_geoip.models.Region(*args, **kwargs)

Region is a some geographical entity that belongs to one Country, Cities belong to one specific Region. Identified by country and name.

class django_geoip.models.City(*args, **kwargs)

Geopoint that belongs to the Region and Country. Identified by name and region. Contains additional latitude/longitude info.

IP ranges

class django_geoip.models.IpRange(*args, **kwargs)

IP ranges are stored in separate table, one row for each ip range.

Each range might be associated with either country (for IP ranges outside of Russia and Ukraine) or country, region and city together.

Ip range borders are stored as long integers

Low-level API usage

Here is an example of how can you guess user’s location:

from django_geoip.models import IpRange

ip = "212.49.98.48"

try:
    ipgeobases = IpRange.objects.by_ip(ip)
    print ipgeobase.city # Населенный пункт (Екатеринбург)
    print ipgeobase.region # Регион (Свердловская область)
    print ipgeobase.country # Страна (Россия)
except IpRange.DoesNotExist:
    print u'Unknown location'

Table Of Contents

Previous topic

Installation

Next topic

High-level API usage

This Page