All geoip data, including geograpy and geoip mapping is stored in the database.
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.
One country per row, contains country code and country name (TBD, #2)
Region is a some geographical entity that belongs to one Country, Cities belong to one specific Region. Identified by country and name.
Geopoint that belongs to the Region and Country. Identified by name and region. Contains additional latitude/longitude info.
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
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'