mirror of
https://github.com/django/django.git
synced 2025-07-19 03:05:32 +00:00
Fixed #18515 -- Conditionally regenerated filename in FileField validation
When a FileField value has been saved, a new validation should not regenerate a new filename when checking the length. Refs #9893.
This commit is contained in:
parent
b6c356b7bb
commit
05d333ba3b
4 changed files with 24 additions and 19 deletions
|
@ -242,7 +242,11 @@ class FileField(Field):
|
|||
# (ie. upload_to='path/to/upload/dir'), the length of the generated
|
||||
# name equals the length of the uploaded name plus a constant. Thus
|
||||
# we can tell the user how much shorter the name should be (roughly).
|
||||
length = len(self.generate_filename(model_instance, value.name))
|
||||
if value and value._committed:
|
||||
filename = value.name
|
||||
else:
|
||||
filename = self.generate_filename(model_instance, value.name)
|
||||
length = len(filename)
|
||||
if self.max_length and length > self.max_length:
|
||||
error_values = {'extra': length - self.max_length}
|
||||
raise ValidationError(self.error_messages['max_length'] % error_values)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue