Automatically connect signals to custom Django model fields -


i've created custom image field django automatically creates thumbnails , other stuff.

from django.db.models.fields.files import imagefieldfile  class imagewiththumbsfieldfile(imagefieldfile):     def __init__(self, *args, **kwargs):         ... 

now automatically connect post_delete signal whenever such field defined in model. know how connect post_delete signal manually when model defined. there way automatically whenever custom field used?

you can in contribute_to_class() method:

class imagewiththumbsfieldfile(imagefieldfile):     ...     def contribute_to_class(self, cls, name, **kwargs):         super(imagewiththumbsfieldfile, self).contribute_to_class(                                                    cls, name, **kwargs)         post_delete.connect(on_delete_callback, sender=cls) 

Comments

Popular posts from this blog

google chrome - Developer tools - How to inspect the elements which are added momentarily (by JQuery)? -

angularjs - Showing an empty as first option in select tag -

php - Cloud9 cloud IDE and CakePHP -