I have a problem with a database imported into Django 1.6.5. In this database the columns follow the pattern: id_city, name, id_state, and so on. But django did not handle it well and I left the class like this:
class City(models.Model):
id_city = models.IntegerField(primary_key=True)
state = models.ForeignKey('State', db_column='id_state', blank=False, null=False)
name = models.CharField(max_length=50, blank=False)
class Meta:
managed = False
db_table = 'city'
To access the id_state field of the table through the template I have two alternatives:
city.state_id
city.state.id_state
In the first alternative it is confusing to work with a name other than the name in the bank, and in the second alternative, an additional query is required to know a single field.
I searched the documentation but did not find a simple way to use the attribute of the way it is in the database, which would look like this:
city.id_state