**form.py** class ImportCCForm(Form): text = CharField(widget=Textarea(), required=False) file = FileField( required=True, label='Select a file', help_text='max 1 megabyte', def save(self): # doing my save data logic here
class FakeModel(object): class _meta: app_label = 'shop' # This is the app that the form will exist under model_name = 'import-cc' # This is what will be used in the link url verbose_name_plural = 'Import CC' # This is the name used in the link text object_name = 'ObjectName' swapped = False abstract = False class ImportCCAdminForm(admin.ModelAdmin): """ This is a funky way to register a regular view with the Django Admin. """ def has_add_permission(*args, **kwargs): return False def has_change_permission(*args, **kwargs): return True def has_delete_permission(*args, **kwargs): return False def changelist_view(self, request): if request.method == 'POST': print(request.read()) form = ImportCCForm(request.POST or None) if form.is_valid(): # Do your magic with the completed form data. # Let the user know that form was submitted. print(form.cleaned_data) # form.save() messages.success(request, 'Congrats, form submitted!') return HttpResponseRedirect('') else: messages.error( request, 'Please correct the error below' ) else: form = ImportCCForm() context = { 'title': 'Import CC', 'opts': FakeModel._meta, 'form': form, } return render(request, 'admin/cc_add_admin.html', context)
<form action="." method="post" enctype="multipart/form-data"> {% csrf_token %} {{ form|crispy }} <input type="submit" value="Submit"/> </form>
Вопрос, почему? Реквест приходит пустой.