I have been trying to style the filefield upload button but since it is run on the forms.py and not on the html, even with ours of investigation, I still don't know how to do it. Is there any way I can style the button? Well the goal is trying to have an icon instead of a button.
models.py
class Post(models.Model):
text = models.CharField(max_length=200)
posti = models.ImageField(upload_to='media/images', null=True, blank="True")
user = models.ForeignKey(User, related_name='imageuser', on_delete=models.CASCADE, default=2)
forms.py (I am missing the posti = form.ImageField under the text variable)
class PostForm(forms.ModelForm):
text = forms.CharField(widget=forms.TextInput(
attrs={
'class': 'form-control',
'placeholder': 'Add a comment...'
}
))
class Meta:
model = Post
fields = ('text', 'posti')
exclude = ['author']
uploadimage.html (It posts the image on the imagelist view)
<div class="container" style="margin-top: 200px; margin-left:50px;">
<form method="POST" enctype="multipart/form-data">
{% csrf_token %}
<div id="formtext" class="overflow-hidden" type="input">{{ form.text }}</div>
<div id="formimage" class="overflow-hidden" type="button">{{ form.posti }}</div>
<button type="submit" class="btn btn-primary mb-2">submit</button>
</form>
</div>