Please tell me how to display the contents of the many-to-many link in the template. For example, there is a model:
class Variety(models.Model): varietyName = models.CharField(max_length=30) def __str__(self): return self.varietyName class Fruits(models.Model): fruitName = models.ManyToManyField(Specs) def __str__(self): return self.fruitName I created the record "Apples" in the table "Fruits", in the table "Variety" I created types of apples (red, green, rotten, etc.) and connected with "Apples" in the table "Fruits". How now is all the right to transfer to the template and display?
To preamera in view.py there is a function, which is triggered when entering the main page. I understand that the values need to pass so?
def index(request): return render(request, 'index.html', {'fruits': Fruits.objects.all()}) If so, how do you get the types of apples in the template?
return "self.fruitName"do not write this way, it is not logical at first, secondly it is wrong. - Sergey Chabanenko