D
D
Dmitry2015-11-11 00:55:12
Django
Dmitry, 2015-11-11 00:55:12

How to set one clean method on many forms at once?

I have one clean method that renames the uploaded photo.
To make it work in all places, you need to put this clean method in all admin forms (and there are quite a few of them throughout the project).
Is it possible to specify one method somehow at once for a number of classes or somehow call it so as not to copy-paste it everywhere?
I tried to write separately, and call it as a function, but it doesn't work out like that.
Here is the clean method just in case:

def clean_images(self):
    self.cleaned_data["images"].name = get_name_datetime(
        self.cleaned_data["images"].name
    )
    return self.cleaned_data["images"]

Thank you.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Ilya, 2015-11-11
@trec

Use inheritance
younglinux.info/oopython/inheritance.php

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question