File tree Expand file tree Collapse file tree 1 file changed +9
-0
lines changed
Expand file tree Collapse file tree 1 file changed +9
-0
lines changed Original file line number Diff line number Diff line change 22import os
33
44from django .conf import settings
5+ from django .core .exceptions import ValidationError
56from django .db import models
67from django .urls import reverse
78from django .utils .translation import gettext as _
@@ -84,6 +85,14 @@ def sync_data(self):
8485 self .file_path = os .path .basename (self .data_path )
8586 self .data_file .write_to_disk (self .full_path , overwrite = True )
8687
88+ def clean (self ):
89+ super ().clean ()
90+
91+ # Ensure that the file root and path make a unique pair
92+ if self ._meta .model .objects .filter (file_root = self .file_root , file_path = self .file_path ).exclude (pk = self .pk ).exists ():
93+ raise ValidationError (
94+ f"A { self ._meta .verbose_name .lower ()} with this file path already exists ({ self .file_root } /{ self .file_path } )." )
95+
8796 def delete (self , * args , ** kwargs ):
8897 # Delete file from disk
8998 try :
You can’t perform that action at this time.
0 commit comments