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.
classMyPictureForm(forms.Form):
pictures = forms.ModelChoiceField(queryset=MyPicture.objects.all())
Solution 2:
you not create a select element in your HTML.
<formaction="{% url 'mypicture' %}"method="post">
{% csrf_token %}
<selectname='picture'>
{% for s in form.pictures.queryset %}
<optionvalue="{{ s.id }}"><imgsrc="{{ MEDIA_URL }}{{ s.logo.url }}"/></option>
{% endfor %}
</select><inputtype="submit"value="Submit"class="btn btn-primary"/></form>
Post a Comment for "Django Choicefield Using Pictures Instead Of Text Not Displaying"