Skip to content

Commit

Permalink
Merge 47a851a into 5161dcf
Browse files Browse the repository at this point in the history
  • Loading branch information
sajadbahar committed Oct 7, 2013
2 parents 5161dcf + 47a851a commit 449b66f
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
7 changes: 7 additions & 0 deletions django_geoip/base.py
Expand Up @@ -79,6 +79,13 @@ def _get_ip_range(self):
:return: IpRange object or None
"""
ip = self._get_real_ip()

# Trying to read custom ip from project setting
try:
ip = settings.LOCAL_IP_ALTERNATIVE
except:
pass

try:
geobase_entry = IpRange.objects.by_ip(ip)
except IpRange.DoesNotExist:
Expand Down
3 changes: 3 additions & 0 deletions docs/installation.rst
Expand Up @@ -62,3 +62,6 @@ In order to make :ref:`user's location detection automatic <highlevel>` several
...
)

* Specify this in :ref:`settings`: to use custom ip for test or use locally:

LOCAL_IP_ALTERNATIVE = '' # custom ip address
5 changes: 3 additions & 2 deletions docs/usage.rst
Expand Up @@ -51,7 +51,8 @@ user's location should be accessible via ``request`` object::
...

``request.location`` is an instance of a custom model that you're required to create on your own
(details below).
(details below), you can get city object by ``request.location.city`` or for some IP doesn't have
city you could get country object by ``request.location.country`` .

.. _location_model_rationale:

Expand Down Expand Up @@ -119,7 +120,7 @@ Very basic implementation of ``GeoLocationFacade`` for demonstration purpose::
def get_by_ip_range(cls, ip_range):
""" IpRange has one to many relationship with Country, Region and City.
Here we exploit the later relationship."""
return ip_range.city.my_custom_location
return ip_range

@classmethod
def get_default_location(cls):
Expand Down

0 comments on commit 449b66f

Please sign in to comment.