Return values in Foreignkey and Manytomanyfield in Django

Asked

Viewed 274 times

0

I have the following Models: Restaurant with a Foreignkey for Cardapio, Cardapio with a Manytomany for Product, Product with a Manytomany for Diapromocao, and I need in the template, display some information such as the restaurant, the product, the normal price of the product and the promotional price of the product. The restaurant and the product I can show, through a method that returns the names of the products in the Cardapio model, but the other information with the normal price and promotional price of the product I can not, someone can give me a help here?

Follow gist link with templates: https://gist.github.com/fandrefh/8f7d1bb5677857031c20

1 answer

0

I don’t think it’s a good idea to format the list of products and prices in the model, you can do this directly in the template.

In the template would look something like this:

{% for produto in cardapio.produtos.all %}
    {{ produto }} {{ produto.preco_promocao }}
{% endfor %}
  • Okay, thank you so much for the answer, but I had already tried this solution, I saw it in other posts right here stackoverflow, but it doesn’t work with me, maybe you’re doing something wrong.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.