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?
I am doing something similar in my
UserProfilemodel. 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:Note that the derived form’s
zipfield is the only one visible to the user.