I'm wondering if there is a convention for naming a foreign key field in Django that is mapped to another field with to_field
. For example, should the Django field name be the model name and the database field name be the column name or is that confusing?
class Stations(models.Model):
name = models.CharField()
observations = models.ForeignKey(Observations,
to_field='zone_code'
db_column='zone_code')
class Observations(models.Model):
zone_code = models.IntegerField(unique=True)
metric_a = models.IntegerField()
metric_a = models.IntegerField()
It doesn't really make sense to have this:
class Stations(models.Model):
name = models.CharField()
observations = models.ForeignKey(Observations,
to_field='zone_code')
class Observations(models.Model):
zone_code = models.IntegerField(unique=True)
metric_a = models.IntegerField()
metric_a = models.IntegerField()
nor this
class Stations(models.Model):
name = models.CharField()
zone_code = models.ForeignKey(Observations,
to_field='zone_code')
class Observations(models.Model):
zone_code = models.IntegerField(unique=True)
metric_a = models.IntegerField()
metric_a = models.IntegerField()
because then you end up with observations_id
or zone_code_id
when the column in the database is actually the zone_code. Anyone have this issue before?