ich das Folgemodell haben:Django Vorlagen iterieren Modellfelder mit Indizes
class UserProfile(...):
...
photo1 = models.URLField()
photo2 = models.URLField()
photo3 = models.URLField()
photo4 = models.URLField()
photo5 = models.URLField()
Und in der Create/Update-Vorlage, ich habe fünf Kopien der folgenden div
für file1
-file5
schreiben:
<div>
Photo 1:
{% if userProfileForm.instance.file1 %}
<a href="{{ userProfileForm.instance.file1 }}" target=_blank>View</a>
{% endif %}
<input type=file name=file1>
{% if userProfileForm.instance.file1 %}
<a href="{% url 'account:deletePhoto' userProfileForm.instance.id %}">Delete</a>
{% endif %}
</div>
Gibt es eine Möglichkeit, Feld file<i>
zu iterieren?
{% for i in '12345' %}
<div>
Photo {{ forloop.counter }}:
...
</div>
{% endfor %}
sein kann jemand helfen Sie erstellen eine Krücke, um Ihr Problem zu lösen, aber IMHO beste Möglichkeit ist, verwandte Modell mit 'Foto' und' Sequenz' Felder zu erstellen –