4

I have an abstract model class responsible for custom validation procedures and a bunch of models in different apps which inherits from this class. And I'm trying to use class_prepared signal to import some app dependent validators, like that:

def on_class_prepared(sender, **kw):
    if issubclass(sender, DefaultModel):
        try:
            getattr(sender, 'class_prepared')(**kw)
        except AttributeError:
            pass
class_prepared.connect(on_class_prepared)


class ValidatableModel(DefaultModel):

    class Meta:
        abstract = True

    @classmethod
    def class_prepared(cls, **kw):
        # knowing cls.__module__
        # here we can import application dependent validators

So now particular class_prepared methods will be invoked once, when apache or whatever starts. Am i right?

4

0 回答 0