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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T14:17:30+00:00 2026-05-19T14:17:30+00:00

In my Django project, let’s say I have the following model: class City(models.Model): name

  • 0

In my Django project, let’s say I have the following model:

class City(models.Model):
    name = models.CharField(max_length=255)
    freebase_id = models.CharField(max_length=255)
    latitude = models.DecimalField()
    longitude = models.DecimalField()
    area = models.IntegerField()

(I’ve omitted the required parameters for DecimalField for simplicity).

The user could enter all the fields manually, but I want to make life easier by letting the user enter some kind of ID in the admin area, like a Freebase ID (such as /en/manchester_united_kingdom), so that we can then use the API to fetch things like latitude, longitude and area.

Long story short, I want to let users provide some ID which can then be used to derive other data inside the model. In an ideal world, the derived fields should be initially hidden in the admin system, but then made visible once populated so that they can be edited.

Is such a thing possible?

  • 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-19T14:17:31+00:00Added an answer on May 19, 2026 at 2:17 pm

    I am doing something similar in my UserProfile model. I have a zip code field that, if it gets filled in by the user, is used to do a geo lookup to get city/state and lat/lng and store them in their respective fields in the model:

    class UserProfile(models.Model):
        user = models.ForeignKey(User, unique=True)
        ...
        zip = models.CharField(max_length=12, blank=True, null=True)
        city_state = models.CharField(max_length=30, blank=True, null=True)
        lat = models.DecimalField(max_digits=12, decimal_places=9, blank=True, null=True)
        lng = models.DecimalField(max_digits=12, decimal_places=9, blank=True, null=True)
    
        def save(self, *args, **kwargs):
            if self.zip:
                (city_state, lat, lng) = get_lat_lng(self.zip)
                if city_state and lat and lng:
                    self.city_state = city_state
                    self.lat = lat
                    self.lng = lng
    
            super(UserProfile, self).save(*args, **kwargs)
    
    class UserProfileForm(ModelForm):
        class Meta:
            model = UserProfile
            fields = ('zip',)
    

    Note that the derived form’s zip field is the only one visible to the user.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's assume we have following models: from django.db import models class Foo(models.Model): name =
Let's say i have several different models in django project. Now i need to
When I have a given django model class like this: class BaseClass(models.Model): some_field =
I have a Django project, let's say project1. Typical folder structure for applications is:
Let's suppose we have these three models: - cagegory ( id, name ) -
Let's say I have a project's urlconf which includes myapp 's urlconf: urlpatterns =
In my django project I have following LOGGING config: LOGGING = { 'version': 1,
I have an existing Django project that has several models using concrete inheritance of
I want to have some constants in a Django Projects. For example, let's say
I have setup a Django project on my laptop and build my first app.

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.