How to solve 'can only concatenate str (not "ManyRelatedManager") to str' in django

429 views Asked by At

What needs to be done to solve this error in django , as i am new in django please help me to solve this.

I tried searching on the web for this solution but got nothing. As much i know the problem is in self.product_name , i want a way to display a manyrealatedmanager.

class cart(models.Model):

    user = models.OneToOneField(User, on_delete=models.CASCADE)
    product_name = models.ManyToManyField(Album)
    qty = models.IntegerField(validators=[MaxValueValidator(15)])
    price = models.IntegerField()
    total_price = models.IntegerField(editable=False)

def save(self, *args, **kwargs):
    self.total_price = self.price * self.qty
    super(cart, self).save(*args, **kwargs)

def __str__(self):
    return str(self.user)+' | '+self.product_name+' | '+str(self.qty)+' | '+str(self.price)+' | '+str(self.total_price)

I am expecting the data in cart.product_name in form of str.

0

There are 0 answers