Зачем нужен def __str__(self) в django [duplicate]
у меня вопрос о функции str(self) в django
Во время чтения одной документации я обнаружил
models.py
class Product(models.Model):
product_name = models.CharField(max_length=200, unique=True)
slug = models.SlugField(max_length=100, unique=True)
description = models.CharField(max_length=250, blank=True)
price = models.IntegerField()
images = models.ImageField(upload_to='photos/products')
stock = models.IntegerField()
is_available = models.BooleanField(default=True)
category = models.ForeignKey(Category, on_delete=models.CASCADE)
created_date = models.DateField(auto_now_add=True)
modified_date = models.DateTimeField(auto_now=True)
def __str__(self):
return self.product_name
что делает это def str(self) do