One suggestion would be to normalize your data, i.e., in your Location table, the Region column is an Integer value, representing one of your Regions. Then create a Regions table that list your region name only once. Thus the Location table just references an index (or Foreign Key) to your Regions table.
For example: your Regions table is something like this:
- id=1, regionname=North America
- id=2, regionname=South America
- id=3, regionname=Central America
- id=4, regionname=Asia/Pacific Islands
Then, your Locations table just indexes this:
- id=1, region=1
- id=2, region=2
- id=3, region=3
- id=4, region=4
- id=5, region=2
- id=6, region=1
Here is a simple, if crude, example:
from elixir import *
metadata.bind = "sqlite:///"
class Regions(Entity):
regionname = Field(String(255))
class Location(Entity):
region = ManyToOne('Regions')
setup_all()
create_all()
#Create the region names:
na_temp = Regions(regionname="North America")
sa_temp = Regions(regionname="South America")
ca_temp = Regions(regionname="Central America")
ap_temp = Regions(regionname="Asia/Pacific Islands")
session.commit()
#Create links to each region in the location table:
northamerica = Location(region=na_temp)
southamerica = Location(region=sa_temp)
centamerica = Location(region=ca_temp)
asiapacific = Location(region=ap_temp)
anotherarea = Location(region=sa_temp)
yetanotherarea = Location(region=na_temp)
session.commit()
#Get all items from the Location table:
locations = Location.query.all()
#Display the contents of the Location table, and lookup the name from the Regions table
for place in locations:
print "Location table id: {}".format(place.region_id)
print "Lookup region name: {}".format(Regions.get_by(id=place.region_id).regionname)
print
There is more than on way to do this, this is just my approach; I'm not the strongest Python programmer you'll meet.