-
Notifications
You must be signed in to change notification settings - Fork 0
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
Update source file details on file change #1760
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -188,6 +188,15 @@ def _save_m2m(self): | |
self.instance.file_as_pdf.delete() | ||
self.instance.ensure_file_as_pdf() | ||
|
||
def clean(self): | ||
cleaned_data = super().clean() | ||
if "file" in self.changed_data: | ||
# clear all the fields that are derived from the file | ||
for field in ["mimetype", "size", "file_as_pdf", "filename"]: | ||
self.instance.__dict__[field] = None | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. that is exactly what There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. or just do it explicitly: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. thanks, updated |
||
|
||
return cleaned_data | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @longhotsummer clearing the fields on the instance from the clean method allows us to compute them again on save. |
||
|
||
|
||
class AttachedFilesForm(AttachmentFormMixin, forms.ModelForm): | ||
class Meta: | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@longhotsummer this is getting called before the source file is saved and updated so we can move it to after the save_related method