Login

Snippets by evilclay

Snippet List

Form and ModelForm inheritance DRY

Modelform cant inhertit from forms. To solve this issue, split thing you wanto to inherit into filed definition and functionality definition. For modelform use the base_fields.update method as mentioned in the code.

  • form
  • inheritance
Read More

Unique FileFiled or FileFiled with custom validation and overwriting files on update

I needed to overwrite files on update (not create new ones) but also a validation which would prevent to upload 2 files with the same name. The CustomCheckFiled triggers a validation passing the filename and model instance. If the validation returns false, the validation error_message will be displayed in admin. The OverwriteStorage is needed because the default storage alters the name if such name already exists. Enjoy.

  • validation
  • FileFiled
  • FileSystemStorage
  • overwrite
Read More

evilclay has posted 2 snippets.