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 4540182
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T15:03:02+00:00 2026-05-21T15:03:02+00:00

Newb here. Apologies in advance. I have: class Place(models.Model): address = models.CharField(max_length=100) […] def

  • 0

Newb here. Apologies in advance.

I have:

class Place(models.Model):
  address = models.CharField(max_length=100)
  [...]
  def coordinates(self):
    location = Location(self.address)
    return location

“Location” method works and is not the problem. I can see Place.coordinates in template just fine but I want to be able to store them in the db and thus, access them in views.py.

My question is, how can I store coordinates in my db so that the calculation is done only once (when the form is initially filled out)?

Thank you! (and I’ve read all the docs, chances are I’ve read over the solution and just don’t understand it, so if this is obvious, you’ll have to excuse me)

  • 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-21T15:03:03+00:00Added an answer on May 21, 2026 at 3:03 pm

    First, define a model for the coordinates:

    class Coordinates(models.Model):
       [whatever coordinates consist of]
    

    Then add coordinates as a field to the Place model.

    class Place(models.Model):
       address = models.CharField(max_length=100)
       [...]
       coordinates = models.ForeignKey(Coordinates)
    

    That way you’ve specified that the coordinates are stored in the db.

    Now, in the view in which you add a new Place to the database, first create the Coordinates and then add the Place to the database:

    def add_place(form):
       address = form.cleaned_data['address']
       coordinates = Coordinates.objects.get_or_create(Location(address))
       [...]
       place = 
          Place.objects.get_or_create(address=address, coordinates=coordinates, ...)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

WP7 newb question here. I have the following code: public class KeyboardHandler : INotifyPropertyChanged
I'm a total newb to LINQ. Here is the code I have so far:
first time poster - semi-newb to Rails. Here is my question. Suppose you have
A bit of a newb here, although I have some experience with Bing Maps.
Newb question here: how can I have the value stored in Maptest[2] update along
I'm somewhat of a git newb so please bear with me here. I have
Newb here. I am instantiating the class below from a Silverlight page's code-behind. I
JS/JQuery Newb here! I have a value stored in variable, and I need to
a newb question here: I have a build.gradle file with apply plugin: java in
Android newb here. Please use small words :-) I'd like to simulate typewriter output

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.