0

enter image description here

How can I remove the clear and change options from the filefield over here? I think I need to modify class ClearableFileInput(FileInput) but I am not sure how. I have tried below-

class MyClearableFileInput(ClearableFileInput):
    initial_text = ''
    input_text = 'cha'
    clear_checkbox_label = ''

to test if it changes the name and it does. I want to remove these fields.

user2715898
  • 921
  • 3
  • 13
  • 20

1 Answers1

0

Instead of trying to extend and modify the widget themselves, I found a solution where I could just retrieve and print the values (i.e. the url of the file) in the template.

Do note that {% load static %} is required for {% get_media_prefix %}

{% load static %}
<table border='1'>
<tr><th>File</th></tr>
{% for form in formset %}
    <tr>
    {{ form.id }}
    <td><a href={% get_media_prefix %}{{ form.file.value }}>{{ form.file.value }}</a></td>
    </tr>
{% endfor %}
</table>
Orphamiel
  • 874
  • 13
  • 22
  • Link to the FieldField class API: https://docs.djangoproject.com/en/3.0/ref/models/fields/#django.db.models.fields.files.FieldFile Link to the get_media_prefix https://docs.djangoproject.com/en/3.0/ref/templates/builtins/#get-media-prefix – Padawan Jan 22 '20 at 20:49