How to save processed excel file (by pandas) in django model?

https://stackoverflow.com/q/75445334/20710209

Could you advise me with a problem in the stack (link)

On this snippet:

class FileForm(forms.ModelForm):
    file = forms.FileField

You’re setting file to a reference of the class forms.FileField, you should create a instance instead.

Yeah, it was typo. Thanks. But it still doesn’t work :slight_smile:

Traceback (most recent call last):
  File "C:\Corrila\DJ\venv\lib\site-packages\django\core\handlers\exception.py", line 55, in inner
    response = get_response(request)
  File "C:\Corrila\DJ\venv\lib\site-packages\django\core\handlers\base.py", line 197, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "C:\Corrila\DJ\lemonshop\demoapp\views.py", line 108, in upload_file
    form.save()
  File "C:\Corrila\DJ\lemonshop\demoapp\forms.py", line 43, in save
    new = pd.read_excel(self.file)

Exception Type: AttributeError at /upload/
Exception Value: 'FileForm' object has no attribute 'file'

You should access the attributes on the cleaned_data not directly from the form.

Tanks a lot. Yeah I figured out. the last one moment is how to save the pandas dataframe object as excel in model instead of uploaded excel. I tried to_excel method but it requires a path object.