Hi,

First of all I would say that I think you should rethink how you store the
ingredients. What I would do is create a recipe model that has a number of
ingredients (an ingredient model with a foreign key to the recipe).
Therefor you would be able to do this in your template:

<h4>Ingredients</h4>
    <ul>
        {% for ingredient in receta.ingredients %}
             <li type="disc">{{ ingredient.name }}</li>
    </ul>

However - if you want to continue with your solution with a fixed number of
ingredients you would be able to do this:
<h4>Ingredients</h4>
    <ul>
        <li type="disc">{{ receta.ingrediente_1 }}</li>
        {% if receta.ingrediente_2 %}<li type="disc">{{
receta.ingrediente_2 }}</li>{%endif%}
        {% if receta.ingrediente_3 %}<li type="disc">{{
receta.ingrediente_3 }}</li>{%endif%}
        {% if receta.ingrediente_4 %}<li type="disc">{{
receta.ingrediente_4 }}</li>{%endif%}
    </ul>

This code assumes that at least ONE ingredient should be present in each
recipe. The others are added when needed.

Regards,

Andréas

Den sön 10 mars 2019 kl 15:24 skrev Barkalez XX <[email protected]>:

> Hello guys,
>
>  I'm learning django and I have some doubts, I suppose that from now on
> you'll see me a lot here because my doubts are endless :).
>
> I'm doing a simple recipe app, and some recipes have more ingredients than
> others and when I render them, empty fields take up space in the rendered
> HTML. I show you how the HTML is. I also include the repo in github.
>
> https://github.com/barkalez/recetas
>
>
>
> [image: Duda1.png]
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To post to this group, send email to [email protected].
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/2c9c280f-0ae2-4e2d-b9d1-3de7e95369df%40googlegroups.com
> <https://groups.google.com/d/msgid/django-users/2c9c280f-0ae2-4e2d-b9d1-3de7e95369df%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAK4qSCc9pLMx6ZW-Opv4oOLNsBSwyYpHyGtF6eNWysFxUe5kFA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to