I'm working with 2 models, each one in a different Django application:
App products:
class Product(models.Model):
name = models.CharField(max_length=256)
price = models.FloatField()
warehouse = models.ForeignKey(Warehouse, on_delete=models.CASCADE)
def __unicode__(self):
return self.name
App warehouses:
class Warehouse(models.Model):
name = models.CharField(max_length=256)
def __unicode__(self):
return self.name
The problem is that in the admin site, when I want to create a product and I need to select a warehouse, I only see the following in the select list:
Warehouse object
Warehouse object
Warehouse object
What do I have to do to see the warehouse name?
__unicode__
方法仅在Python 2中使用。由于您大概使用的是Python 3,因此应改为定义__str__
。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.