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

  • Home
  • SEARCH
  • 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

This is an odd thing I've just run into. I have a web application
I have this dictionary in my apps model file: TYPE_DICT = ( (1, Shopping
I have a User model and a Submission model. Each Submission has a ForeignKey
I think this is pretty typical, you have the same website project with an
I think this must be simple but I can't get it right... I have
I don't think this can be done cleanly, but I'll ask anyway. I have
I have read the documentation on this and I think I understand. An AutoResetEvent
For example, I have a custom control called SampleControl. To simplify things for this
I think I have a solution to this, but is there a better way,
This follows a couple of other questions (but I think I have refined my

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.