User:Babbage Linden/Django/ORM
Jump to navigation
Jump to search
Django provides a powerful object relational mapper which can generate database schema and SQL queries from python object descriptions or generate python classes to describe an existing database schema:
class Simulator(models.Model):
sim_name = models.CharField(max_length=105)
grid_x = models.IntegerField()
grid_y = models.IntegerField()
host_name = models.CharField(max_length=300, blank=True)
start_time = models.DateTimeField()
access = models.IntegerField()
region_id = models.CharField(primary_key=True, max_length=108, blank=True)
estate_id = models.IntegerField()
enabled = models.CharField(max_length=3)
status = models.CharField(max_length=24)
external_host_ip_string = models.CharField(max_length=45, blank=True)
host_port = models.IntegerField(null=True, blank=True)
pid = models.IntegerField(null=True, blank=True)
simstate_asset_id = models.CharField(max_length=108, blank=True)
priority = models.IntegerField()
sim_cpu_ratio = models.IntegerField()
needs_genids = models.CharField(max_length=3)
telehub_local_x = models.FloatField(null=True, blank=True)
telehub_local_y = models.FloatField(null=True, blank=True)
telehub_local_z = models.FloatField(null=True, blank=True)
is_prelude = models.CharField(max_length=3)
class_id = models.IntegerField()
seq = models.IntegerField()
first_occupied = models.DateField(null=True, blank=True)
status_updated = models.DateTimeField()
needs_wash = models.CharField(max_length=3)
island_fee = models.DecimalField(null=True, max_digits=11, decimal_places=2, blank=True)
island_bill_date = models.DateField(null=True, blank=True)
simstate_url = models.CharField(max_length=765, blank=True)
version = models.CharField(max_length=96, blank=True)
channel = models.CharField(max_length=384, blank=True)
class Meta:
db_table = u'simulator'
The models are kept separate from the views, allowing schema and API to vary independently.