Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3432150
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T07:24:49+00:00 2026-05-18T07:24:49+00:00

i have this thing in my models.py file user = models.ForeignKey(‘auth.User’, unique = True)

  • 0

i have this thing in my models.py file

        user = models.ForeignKey('auth.User', unique = True) 
        latitude = models.DecimalField(max_digits=8, decimal_places=6)
        longitude = models.DecimalField(max_digits=8, decimal_places=6)
        Availability  = models.CharField(max_length=8,choices=STATUS_CHOICES, blank= False, null=False)
        Status = models.CharField(max_length=50, blank = True, null= True)

and in forms.py i have

class registerForm(forms.ModelForm):

      class Meta:
        model=register
          fields = ('latitude', 'longitude', 'Availability', 'Status')

now what i want here is to geocode the Ip address of the user and get the latitude and longitude automatically after geocoding the IP and save it to the database. i dont want to allow the user to enter the latitide and longitude manually as it will be an odd one and definately nobody will like to do it manually.
i am using GeoIP to geocode the IP address. and in my views.py i have

def Userlocation(request):
    if request.method == "POST":
        rform = registerForm(data = request.POST)
        if rform.is_valid():
            register = rform.save(commit=False)
            register.user=request.user
            register.save()
            return render_to_response('home.html')
    else:
        rform = registerForm() 
    return render_to_response('status_set.html',{'rform':rform}) 

i am looking for a way to automatically get the lat,lon from the GeoIP and place it in the latitude longitude field in forms so that the users do not have to manually enter it. and then after entering the status and availability the forms can be saved to database.
any help would be greatly appreciated

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T07:24:50+00:00Added an answer on May 18, 2026 at 7:24 am

    Overwrite the save method of form to populate latitude & longitude

    from django.contrib.gis.utils import GeoIP
    class registerForm(forms.ModelForm): 
        class Meta:
            model=register
            fields = ('Availability', 'Status')
    
        def save(self, ip_address, *args, **kwargs):
            g = GeoIP()
            lat, lon = `get the lat & lng`
            user_location = super(registerForm, self).save(commit=False)
            user_location.latitude = lat
            user_location.longitude = lon
            user_location.save(*args, **kwargs)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this thing working mostly. What I don't get is, if I have
I have this thing that i need to do and some advices will be
I swear, I have this exact thing working on another page. I'm such a
I have this Java code, and I want to do the same thing in
I have this code (C#): using System.Collections.Generic; namespace ConsoleApplication1 { public struct Thing {
Here is the thing. Right now I have this e-commerce web site where people
I have to ask this, because: The only thing I recognize is, that if
I would have thought that this would be an easy thing to do, but
Does anyone have any experience with this sort of thing? I'm talking about applets
I am pretty new to this iPhone dev thing but so far I have

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.