Subclassing the Django ImageFileField

后端 未结 2 519
醉梦人生
醉梦人生 2021-02-11 09:36

I\'m interested in subclassing django\'s ImageFileField to allow access to the image IPTC metadata, something like:

>>> from myapp.models import SomeMod         


        
2条回答
  •  天命终不由人
    2021-02-11 10:04

    It's not clear from your question: have you tried something like this?

    class ImageMetadataMixin(object):
        """Mixin can be added to any image file"""
        @property
        def iptc(self):
            """Or something like this"""
    
    class ImageWithMetadataFieldFile(ImageMetadataMixin, ImageFieldFile):
        pass
    
    class ImageWithMetadataField(ImageField):
        attr_class = ImageWithMetadataFieldFile
    

    I think it's all what necessary. Why do you think you need to redefine descriptor_class?

提交回复
热议问题