1๐
โ
I think what you need is a custom form. You can validate whatever you want in clean_<field>
method of your form. It should be similar to this:
class InfoFromFileForm(ModelForm):
def clean_File(self):
file_obj = self.cleaned_data['File']
hash = get_hash() # whatever you use to get file hash
if InfoFromFile.objects.filter(file_hash=hash).exists():
raise ValidationError(_("The hash must be unique.")
return file_obj
Then in your admin class
class InfoFromFileAdmin(admin.ModelAdmin):
# your things
form = InfoFromFileForm
# more things
๐คKarolis Ryselis
Source:stackexchange.com