I have created two Django models, were a field from one model is a Foreign key to another (as per below).
class Units(models.Model):
name = models.CharField(max_length=10, primary_key=True)
symbol = models.CharField(max_length=5)
class Targets(models.Model):
name = models.CharField(max_length=100)
unit = models.ForeignKey(MicroNutrientUnits)
...
These models are then registered to the admin site via admin.site.register
. When adding an item to table Target unit correctly reflects items from table Units, however are represented in a dropdown with the name Units objects for each entry.
How can I set the name in the admin dropdown to Units.name in the admin config page?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…