django-forms

How to upload multiple files from the Django admin?

心已入冬 提交于 2020-12-04 06:40:32
问题 I want to upload multiple files in the Django admin, without having to place multiple FileField fields. The user can be able to manage the files in a simple way; delete or change each uploaded file but upload several at once. the solution I see viable is to use several filefield but the problem is, i dont know how many files the user will upload def case_upload_location(instance, filename): case_name = instance.name.lower().replace(" ", "-") file_name = filename.lower().replace(" ", "-")

Two different submit buttons in same form in Django

牧云@^-^@ 提交于 2020-12-03 07:31:53
问题 I have an UpdateView in Django. I have just a normal submit button. When the object is updated correctly it redirects to an object list via success_url . Can I make two different submit buttons: One button which submits and redirects to objects list page (ListView) and another button which submits and redirects to the object detail page (DetailView)? I don't know how to do this in a smart way. 回答1: Since you're submitting to the same place, and only want to change the redirect destination

Django UpdateView disable some fields

南笙酒味 提交于 2020-11-27 04:04:38
问题 I have made a class view inheriting UpdateView. I have specified the fields and models from which the forms should be built. Now say if i have a field email, then I want to disable it in the form. I have no clues as to how it can be done. class UserUpdate(UpdateView): model = Users fields = ['email', 'first_name', 'last_name', 'birth_date'] template_name = 'users_update_form.html' success_url = '/index/' 回答1: To hide it: class UserUpdate(UpdateView): model = Users fields = ['first_name',