considering the following code:
models.py
class Manufacturers(models.Model):
name = models.CharField(max_length=32)
class Cars(models.Model):
producedby = models.ForeignKey(Manufacturers)
forms.py
class CreateCar(forms.ModelForm):
class Meta:
model = Cars
… on the html page the “producedby” field appears like a list of “Manufacturer object” choices, which is not very useful, is it possible to display the Manufacturer.name field instead?
I have tried solutions suggested in other threads but none of them worked.
Many thanks for your help
I fixed it by overloading the __str__ method and returning the name as follows: