I have a model in django with a 'compound primary key' setup via unique_together.
for the model below can I set up the str() result so that it display both fields, (name and supplier)
class Product(models.Model):
name = models.CharField(max_length=255)
supplier = models.ForeignKey(Supplier)
# some other fields
def __str__(self):
return self.name
class Meta:
unique_together = ('name', 'supplier')
So that it will also appear in a related model eg.
class ProductPrices(models.Model):
name = models.ForeignKey(Product)