Skip to content

Commit 41c5d7e

Browse files
committed
fix: import error
1 parent 12f2868 commit 41c5d7e

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

papers/models.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,20 @@
33
import textwrap
44

55
from django.contrib.auth.models import User
6+
from django.core.exceptions import ValidationError
67
from django.db import models
78
from django.db.models.signals import pre_delete
89
from django.utils import timezone
910
from django.core.validators import MinValueValidator, MaxValueValidator
1011

12+
MAX_FILE_SIZE = 50 * 1024 * 1024 # 50 MB
13+
14+
15+
def validate_file_size(value):
16+
"""Validate whether the uploaded file size is within the allowed limit (MAX_FILE_SIZE)."""
17+
if value.size > MAX_FILE_SIZE:
18+
raise ValidationError(f'Maximum file size is {MAX_FILE_SIZE / (1024 * 1024)} MB.')
19+
1120
class NotificationPeriod(models.Model):
1221
name = models.CharField(max_length=64)
1322
period = models.IntegerField() # in seconds
@@ -93,7 +102,7 @@ def paper_directory_path(instance, filename):
93102

94103
class UploadedFile(models.Model):
95104
paper = models.ForeignKey(Paper, on_delete=models.CASCADE)
96-
file = models.FileField(upload_to=paper_directory_path, blank=True,max_length=512)
105+
file = models.FileField(upload_to=paper_directory_path, blank=True, max_length=512, validators=[validate_file_size])
97106
created_at = models.DateTimeField(default=timezone.now)
98107

99108
def filename(self):

0 commit comments

Comments
 (0)