Skip to content

When overriding save of a model, how to access filefield? #53

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

Open
FireRedDev opened this issue Sep 11, 2022 · 0 comments
Open

When overriding save of a model, how to access filefield? #53

FireRedDev opened this issue Sep 11, 2022 · 0 comments

Comments

@FireRedDev
Copy link

FireRedDev commented Sep 11, 2022

Hey, i am trying to do the following:

class Upload(models.Model):
    upload_file = models.FileField(upload_to='media', blank=True, null=True)
    dataframe_from_transformed_uploadfile = PickledObjectField(blank=True, null=True, editable = False)
    pivoted_dataframe_from_transformed_uploadfile = PickledObjectField(blank=True, null=True, editable = False)
    pivotedlist_dataframe_from_transformed_uploadfile = PickledObjectField(blank=True, null=True, editable = False)
    upload_date = models.DateTimeField(auto_now_add =True)
    order_description = models.TextField(default="")

    def save(self, *args, **kwargs):
        generatereport(self)
        super(Upload, self).save(*args, **kwargs) # Call the "real" save() method.

    
def generatereport(self):
    df = pd.read_excel(os.path.join('media',self.upload_file.name))

However at the read excel part i get:

FileNotFoundError at /report/
[Errno 2] No such file or directory: 'media\\bgbrgbruckleitha_orderlist.xlsx'

If i try it with .path instead of .name i get NotImplementedError at /report/ , probably because its not supported?

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

1 participant