By convention django places the class Meta:
declaration second to last in the class definition, right before the __unicode__
method definition. Is this required? I'm trying to trace an insidious error on Lion OSX where the case (capital/lower) of a db_table = u'TableName'
statement is being ignored for some models. For some models manage.py syncdb
creates mysql tables with the lower()
ed table names and for others it uses the db_table
case properly. The more complicated models, with custom save()
and other methods are the ones that are converted to lowercase before creating mysql tables. I'm trying lots of code rearranging to see if that's the issue, but can't find documentation for the proper order of things, though I recall in the past somewhere that a position for class Meta:
was specified.
Also tried both unicode literals for the db_table spec and single-byte string literals. Niether make a difference (for the working or the nonworking models)
Here's the relevant code:
grep -A5 -B2 _table 'entityorganizer/models.py'
class Meta:
db_table = 'Entity'
verbose_name_plural = "entities"
ordering = ["map_status","type_name","name"]
get_latest_by = "updated"
--
class Meta:
db_table = 'EntityRelationship'
ordering = ["to_entity","relationship_type"]
unique_together = (('from_entity','to_entity','relationship_type'))
get_latest_by = "updated"
verbose_name = "relationship"
--
class Meta:
db_table = 'Specialty'
verbose_name_plural = u'specialties'
def __unicode__(self):
return '%s'%(self.specialty)
--
class Meta:
db_table = 'ZipCode'
get_latest_by = "updated"
def get_region(self):
return REGION[region_id_v2-200][1] or 0
--
class Meta:
db_table = 'Setting'
def __unicode__(self):
return '%s = %s'%(self.name, self.value) #, self.updated)
You can put your class Meta
wherever you want in your models, so long as it matches the correct indentation.