Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FileField not working for django-file-resubmit #22

Open
AmeyKelekar opened this issue Aug 13, 2018 · 3 comments
Open

FileField not working for django-file-resubmit #22

AmeyKelekar opened this issue Aug 13, 2018 · 3 comments

Comments

@AmeyKelekar
Copy link

AmeyKelekar commented Aug 13, 2018

Hi,

I am referring https://github.com/un1t/django-file-resubmit that will help me not to reselect file on a Validation Error. But somehow I am not able to implement that functionality using 'file_resubmit'

I will share the steps followed:

  1. pip install django-file-resubmit

  2. In settings. py:

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    ...
    'file_resubmit',
]

CACHES = {
    'default': {
        'BACKEND': 'django.core.cache.backends.locmem.LocMemCache',
    },
    "file_resubmit": {
        'BACKEND': 'django.core.cache.backends.filebased.FileBasedCache',
        "LOCATION": '/tmp/file_resubmit/'
    },
}
  1. models.py has following line for file upload:

document_copy_of_CDA = models.FileField(upload_to='documents/%Y/%m/%d', validators=[validate_file_extension])

  1. admin.py has following lines:
from django.contrib import admin
from file_resubmit.admin import AdminResubmitMixin
from .models import Consulting

class ConsultingAdmin(AdminResubmitMixin, admin.ModelAdmin):
    pass

admin.site.register(Consulting, ConsultingAdmin)

  1. forms.py has following lines:

from file_resubmit.admin import AdminResubmitImageWidget, AdminResubmitFileWidget

class ConsultingForm(forms.ModelForm):
    class Meta:
	model = Consulting
	exclude = ('user', 'status')
	widgets = {
		'picture': AdminResubmitImageWidget,
		'file': AdminResubmitFileWidget, 
	}

Can you please check and let me know if I have to do any kind of modifications or addition to my exisiting code to take advantage of resubmit functionality?
Thanks in advance.
Looking forward to hearing from you.

Regards,
Amey Kelekar

@luyidong
Copy link

luyidong commented Sep 16, 2018

Me too , with Django 1.10.6

forms.py has following lines:

        widgets = {
            'file': AdminResubmitFileWidget,
          }

resubmit to detect web content:

 name="file_cache_key"   

field already exists ,but it also prompts need to reselect the file

...

How to fix it?

@maddencs
Copy link
Collaborator

Can you explain what exactly is happening? I've created a test project in Django 1.10.6 that mimics @AmeyKelekar 's post, but I don't have any problem uploading files via admin. While I do see the text that says "No File Selected"(I'll look into trying to remove that), it still retains the file for me.

@luyidong
Copy link

I know why form https://github.com/un1t/django-file-resubmit/issues/2

@un1t  said:
Hi! You can't set value to file input in browsers due to security reasons. 

Therefore widget renders filename near a file input. If you have any ideas how to fix it let me know.

--

I need to customize page content to avoid duplicate input.

hughrun added a commit to bookwyrm-social/bw-file-resubmit that referenced this issue Nov 5, 2023
Hide the file picker when a file has been retained in cache for 'resubmiting'.
Also updates README and RC version

Should resolve these issues from django-file-resubmit:

un1t/django-file-resubmit#21
un1t/django-file-resubmit#22

and shortly...
un1t/django-file-resubmit#28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants