python - Upload CSV file in django admin list view, replacing add object button -


i want replace add object button in listview of admin page. underlying idea administrator can download data on models in db, use tool edit data, , reupload csv file.

in list view struggling override form, setting

class somemodelform(forms.form):     csv_file = forms.filefield(required=false, label="please select file")  class meta:     model = mymodel     fields = '__all__'  class somemodel(admin.modeladmin):     change_list_template = 'admin/my_app/somemodel/change_list.html'      form = somemodelform      other stuff 

the admin change_list.html overridden follows:

{% extends "admin/change_list.html" %} {% load i18n admin_urls admin_static admin_list %}  {% block object-tools-items %}      <form action="{% url 'admin:custom_submit_row' %}" method="post" enctype="multipart/form-data">         {% csrf_token %}         <p>             {{ form.as_p }}         </p>         <p><input type="submit" value="upload" /><input type="reset" value="reset"></p>     </form> {% endblock %} 

previously somemodel missing class meta, per sebbs response updated. original error has been resolved admin page displaying upload , reset buttons no field file uploads.

cheers

edited sebb's input below. sebb. error fixed

< class ‘my_model.admin.somemodeladmin'>: (admin.e016) value of 'form' must inherit 'basemodelform'

to class somemodelform add this:

class meta:         model = yourmodel         fields = '__all__' 

and change forms.form forms.modelform


Comments

Popular posts from this blog

angular - Is it possible to get native element for formControl? -

unity3d - Rotate an object to face an opposite direction -

javascript - Why jQuery Select box change event is now working? -