0

I want implement feature: saving the city of an unregistered user in my django app.

Example

  1. I visited the site for the first time. And chose my city. (not registerd)

  2. I visited the site for the second time. Site identified my city.

How can I do It with django?

P.S. Could you please recommend articles or materials?

Example of the site https://edadeal.ru/ (you can chose city in the top right corner red text)

mascai
  • 1,373
  • 1
  • 9
  • 30

2 Answers2

1

I would recommended reading this question to understand how to retrieve IP address and location via GeoIP. This can then be stored as part of a model within the db.

You could get the code to check the db to see if the IP has previously appeared and if not then store it with the associated city.

Lewis
  • 2,718
  • 1
  • 11
  • 28
1
  • Have the user enter their postal/zip code first, in a popup.
  • Then, I would use a webservices API like EZCMD.com to get a list of nearby cities, which the user will then select based on their postal code.
  • Then store that list in a cookie along with an anonymous user unique token. When the user comes back to the site, check for the cookie.
  • Check the token against your database for people who have visited the site and entered their postal/zip code.

To get the list of cities to put in your form you can do something like:

$.getJSON('https://ezcmd.com/apps/api_geo_postal_codes/nearby_locations_by_zip_code/GUEST_USER/-1?zip_code=90210&country_code=US&unit=Km&within=5', function(data){
    //extract the data you need for your form here. This API might be best for the US, 
    //don't know about Russia.
    console.log(data);
});

See jsfiddle to play with the API.

You can use this to set a cookie

Use this to set a unique token

Lawrence DeSouza
  • 984
  • 5
  • 16
  • 34