Есть модель
CategoryProducts у которого есть поля
title,
products... Поле products имеет отношение в ManyToMany, и мне нужно отобразить в функции
def __str__ кол-во.
class CategoryProducts(models.Model):
class Meta:
verbose_name_plural = "Продукция"
title = models.CharField(max_length=255, verbose_name='Название', db_index=True)
products = models.ManyToManyField(to='Products', related_name="product", db_index=True, blank=True, verbose_name='Продукты')
def __str__(self):
return '{}, ({})'.format(
self.title, self.products
)