Django Choicefield Using Pictures Instead Of Text Not Displaying
I'm trying to do something which should be straightforward, but I cannot have it work properly. I would like to display images in a grid, with let's say 4-6 images per column and b
Solution 1:
Where did you defined pictures
field in form? Or is your form a forms.ModelForm
instead of forms.Form
?
I think you should put that outside __init__
, or maybe we are missing some part of code.
class MyPictureForm(forms.Form):
pictures = forms.ModelChoiceField(queryset=MyPicture.objects.all())
Solution 2:
you not create a select element in your HTML.
<form action="{% url 'mypicture' %}" method="post">
{% csrf_token %}
<select name='picture'>
{% for s in form.pictures.queryset %}
<option value="{{ s.id }}"><img src="{{ MEDIA_URL }}{{ s.logo.url }}"/></option>
{% endfor %}
</select>
<input type="submit" value="Submit" class="btn btn-primary"/>
</form>
Post a Comment for "Django Choicefield Using Pictures Instead Of Text Not Displaying"