1👍
✅
You can access the related Publisher
instance through the ForeignKey field and get the publisherName
in the __str__()
method so:
def __str__(self):
publisher_name = self.publisher.publisherName
return f'{self.pencilerName} ({publisher_name})'
Additionally, I’d recommend you to use string formatting, such as using f-strings.
0👍
It is as simple as that:
def __str__(self):
return f"{self.pencilerName} ({self.publisher})"
- [Answered ]-Django ClearableInputField in form doesn't render in HTML
- [Answered ]-Database design for Django review website
- [Answered ]-Django and jQuery: timing
Source:stackexchange.com